Part of the the magic of object chainability and a well designed 
framework (in any language) is that it really encourages simple and 
clean looking code.
If your code starts looking convoluted, then you probably aren't doing 
something right and there probably IS a simpler solution.
-Zach

Steve Jones wrote:
> Hi Jake,
>
> Well, Its good to see that the discussion reared up there!! Rather 
> than a general discussion about use of ID / class, I think its helpful 
> to look at how best to achieve a result specifically with jQuery, as 
> core operators can sometimes make a particular task much easier than 
> you'd think.
>
> As a result of your statement, Karl Swedburg posted some code which 
> shows jQuery at its elegant best, all using classes in a situation 
> where I would normally have used IDs.
>
> To recap, my original problem was that I wanted each of four instances 
> of <a class="open_button"> to open a corresponding DIV <div 
> id="section0">, <div id="section1"> etc. and was trying to iterate 
> through the <a> objects applying the appropriate "click" method.
>
> Then the "IDs are a crutch..." response came. You had suggested 
> linking the elements by giving them a common class:
>
> Quote: <a class="open_btn section1"....> with the <div class="closed 
> section1">
>
> However, I had not realised the potential for jQuery to dispense with 
> numerical identifiers altogether!
>
> Karl's solution - which is just beautiful:
>
>   $("a.open_button").each(function(index) {
>     $(this).click(function() {
>       $('div.section:eq(' + index + 
> ')').addClass('open').slideToggle(1200,function() {
>         complete(index);
>       });
>       return false;
>     });
>   });
>
> The power of course lies in the statement $('div.section:eq(' + index 
> + ')') - now all I need to do is have <a class="open_button> and below 
> it <div class="section"> - no numeric identifiers, as jQuery is doing 
> the work iterating through the array of matching objects.
>
> Thanks,
>
> Steve Jones
>
>
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to