> > That would work fine, but it involves parsing the ID for a name
> > component that is "common" to the link and the DIV.
>
> Yes, indeed, that is exactly what you would do. But it's so simple - it
> takes less code to do it than describe it. For example:
>
>     $(function() {
>         $('#left a').click( function() {
>             $( '#' + this.id.replace( '_link', '_div' ) ).doSomething();
>         });
>     });
>
> Or another way to do the same thing:
>
>     $(function() {
>         $('#left a').click( function() {
>             $( '#' + this.id.split('_')[0] + '_div' ).doSomething();
>         });
>     });
>
> Or if you have several related elements to operate on:
>
>     $(function() {
>         $('#left a').click( function() {
>             var base = '#' + this.id.replace( '_link', '_' );
>             $( base + 'div' ).doSomething();
>             $( base + 'navlink' ).doSomethingElse();
>             $( base + 'whatever' ).doWhatever();
>         });
>     });
>
> What's not to like?

One thing I can think of is that you need to rely on the id's being in
a certain format, e.g you're creating a dependency of client-side and
PHP code. (Re-)using the hash makes it agnostic of the format of the
id.

--Klaus

Reply via email to