.getChildren( [ immediate ] ) - Get all child elements or immediate children
.getChildren() will fetch all or only immediate child elements and wrap them into Nedil Objects.
Parameters
Returns
Example 1
.getChildren() gets all the children of #parent and returns as Nedil Objects. Using Chil Nedil Onjects, we style the background color of children. "style" function is explained under Utilities.
JS
HTML
CSS
$.domLoaded(function() { $.get("#change").on("click", function() { //get all children var chil = $.get("#parent").getChildren(); chil.style("background-color", "red"); }); });
Result
Example 2
.getChildren() can also be used to fetch only the immediate (direct) children. Following example takes only the immediate children of #parent and changes their background color.
JS
HTML
CSS
$.domLoaded(function() { $.get("#change").on("click", function() { //get only immediate children var chil = $.get("#parent").getChildren(true); chil.style("background-color", "red"); }); });
Result
| |||||||||||||||||