jQuery's selectors are very useful, but different than what you'd expect...
As i'm sure you know, it uses css selectors to determine which element(s) are being selected to be manipulated. As a result, a single call can result in many, many elements being selected and available to be poked and prodded...
I'll try to outline a few different examples:
Code: Select all
$('p').hide(); // hide EVERY SINGLE paragraph found on a page
$('#nav a').hide(); //hide all anchors (links) within the element with an id of 'nav'
$('#nav ul ul').hide(); //hide all nested UL's within the element with an id of 'nav' (useful for drop down menus)
// a favourite of mine, this will add a class name of 'active' to each anchor (link) element found within the element with the id of 'menu', but only the one(s) that have the current page name (this page would be 'posting.php') at the end it's href element. (used to highlight the current page)
$('#menu a[@href$=' + location.pathname.substring(1) + ']').addClass('active');
$('#menu a').click(function(){this.blur();}); //this is a workaround for a small firefox annoyance, where the outline around the link you just clicked stays there until you click elsewhere.
jQuery can be a real pain in the arse, but stick with it, read their docs and mailing list, post here, and most importantly, PLAY! It's much easier to learn how it works when you take a normal page, with lots of different elements, and just take your time determining how to select the element or elements you want to work with.
Hope this helped a little
