jQuery Selector can be used to find (select) HTML elements from the DOM. Once an element is selected, the jQuery children() method is called to find all the child elements of the selected element. To loop through the child elements, the jQuery each() method is used as demonstrated in the following example.
Example 1: The sample HTML page contains a “container” div having some child elements. Looping is done throughout all the child elements of the “container” div and then copied them to the “output-container” div which initially had no child elements.
Example 2: In the above example, looping is implemented through all the child elements. But if it is required to loop for some specific child elements or elements with some specific class or id, then it is passed as an argument to the children() function as demonstrated below.
The above example demonstrates all the three cases, looping over specific child elements, looping over child elements with a specific id, and looping over child elements with a specific class.
Please Login to comment...