Yes Steve an element can have "two classes". :) The "class" attribute of an element contains a list of space seperated "words". Think of them more has "tags" rather than actual "OO programming" classes.
Karl Rudd On 1/21/07, Steve Jones <[EMAIL PROTECTED]> wrote: > A question about toggleClass... everything below works, so its not a > problem as such... > > http://www.g-raff.co.uk/jquery/basic.html > > I added a statement to the code to change the appearance of headings > that had been clicked, and back again when they were clicked a second > time. > > function init() { > // set first section to be open on launch > $("a.open_btn:eq(0)").toggleClass("down_state"); > > // now iterate through <a class="open_btn"> objects to add click > methods to open corresponding <div class="section"> > $("a.open_btn").each(function(index) { > $(this).click(function() { > $(this).toggleClass("down_state"); > $('div.expandedSection:eq(' + index + > ')').slideToggle("normal"); > return false; > }); > }); > }; > > What I'm wondering about are the inner workings of toggleClass. > > In the script above, I have applied the click method to all instances > of a.open_btn - but of course when it's clicked, there is a "change > of class" to .down_state - yet the click method still works. > > I'm just wondering how the toggleClass method is implemented, as this > seems like voodoo to me - an element can't have 2 classes, can it? > Yet, when an "a.open_btn" becomes "a.down_state", it still retains > the click methods belonging to instances of "a.open_btn" - don't get > me wrong, I'm glad it works! But I'd prefer to understand WHY it works. > > I think I might give up Flash. This is too good... > > Cheers > > SJ > > > > > > > > > > > > > _______________________________________________ > jQuery mailing list > [email protected] > http://jquery.com/discuss/ > > > > _______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
