Example of .children() in jQuery
April 28, 2013
.children() in jQuery selects all the child DOM element and on those selection other jQuery function can be applied. .children() is called on parent DOM element but it applies only on children elements. Syntax is
$("div").children()
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <div>Inside first div, no other DOM element</div> <div>Inside second div <span>span element</span></div> <div>Inside second div <i>i element</i> and <b>b element</b> </div> <script>$("div").children().css("color", "blue");</script> </body> </html>
Output
Inside first div, no other DOM element
Inside second div
span element
Inside second div
i element
and
b element