jquery hide first child
NOTE: This is a very old migrated blog post. It may have incorrect formatting.Well I recently picked up and finished a book on JQUERY, which to some may be a bit boring, but for me was an excellent read while taking a vacation in Maine! Anyways, one of the many things I learned about Jquery was using their nth-child selector functionality, enabling me to select and do anything I want with any particular child of a group. In the case you're finding this blog entry, it's because you want to use Jquery to hide the first child of a particular element.
$("body div#content div:nth-child(1)");
The above code will go into the body element, grab the div with an ID of content, and then grab it's first DIV. Not bad, except we want to hide it right?
$("body div#content div:nth-child(1)").hide();
Wow, that was easy! What about making a link that toggles the display of a particular element?
$("button").click(function () {
$("body p:nth-child(1)").toggle();
});
Now we've got cod where any button will toggle the display of the first paragraph of our body when clicked. Jquery really does make this stuff a breeze!