<div id="lnk">
<a href="index.html" id="homeLnk">Home</a>
<br><a href="about.html" id="aboutLnk">About Us</a>
<br><a href="contact.html" id="contactLnk">Contact Us</a>
</div>
alert( $("#lnk").children("a").length ); // 3
Caveat: it's important to specify a selector argument for the children() function, otherwise all child nodes are counted; the code below returns "5" - guess why (show answer) . alert( $("#lnk").children().length ); // 5
alert( $("#lnk").children("#aboutLnk").length ); // 1
...or use this shortcut notation with descendant selector, which literally means "find this child node and see if it has this other element as parent": your code becomes shorter and more readable! alert( $("#lnk #aboutLnk").length ); // 1
Tip: that exact same technique can be used to check if an element exists on the page.
if( $("#lnk").has("#aboutLnk").length )
alert( "First element contains the one passed to has() !" );
if( $("#lnk #aboutLnk").length )
alert("This child element exists!"); // Do something useful here...
else
alert("This element wasn't found.");
Note: the first line evaluates to true if at least one match found; you can use the same approach to check if multiple children elements exist as well with "if( $("#lnk").children("a").length )".
// Check for links pointing to "about.html"
if( $("a[href*='about.html']").length )
alert("There *is* a link pointing to About on this page!");