@Klaus Hartl -- Actually, the code I displayed was simply dummy code
as an example; the real code either links to real URIs or isn't an A
tag at all.

Your usage of the hash property, however, does not really provide any
more information than the same text used as an ID. So it's an
alternative solution, but not really any more efficient.

I suppose that my problem is conceptual more than anything, since I am
also writing the PHP code that generates the output. My PHP code KNOWS
-- at the moment that output is being generated -- what the IDs of all
the related components are ("m1_div, m1_link, m1_navlink"). So it was
convenient to hard-code these values in an inline onclick handler.

The demands of jQuery-style javascript, however (and I'm not arguing
about the logic of this method), is that my PHP code should ignore the
information it has, and Javascript will re-create that information by
parsing information from the link (whether in the hash or the ID)
later on. It seems like extra work, but it does make things more
flexible.

spud.

On Dec 26, 6:45 pm, Klaus Hartl <klaus.ha...@googlemail.com> wrote:
> You said you don't want to litter your code with bogus classes, but -
> speaking of unobtrusive - you do litter it with bogus anchors
> (href="#"). That said, the most obvious solution to me is to give
> these anchors a little more meaning by letting them point to the div
> they seem to be connected to anyway:
>
> <a href="#m1_div">Module 1</a>
>
> Such semantically improved HTML will also make your scripting easier
> (and theoretically - even if it may be not too much of a concern in a
> CMS, it will degrade more gracefully).
>
> In your jQuery code you can then easily rely on the hash property to
> access the associated elements, thus you get a pretty generic,
> straightforward solution:
>
> $('a').click(function() {
>     var fragment = $(this.hash); // a div in our case
>     // do something with fragment, for instance toggle
>     // so something else
>
> });
>
> --Klaus

Reply via email to