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.
- jQuery | :nth-child() Selector
- jQuery | :nth-last-child() Selector
- jQuery | :first-child Selector
- jQuery | :last-child Selector
- jQuery | :only-child Selector
- jQuery | parent > child Selector
- How to count child element using jQuery ?
- How to iterate through all selected elements into an array ?
- What are the efficient ways to iterate over all DOM elements ?
- How to select all child elements recursively using CSS?
- How to get specific number of child elements using CSS?
- How to remove parent element except its child element using jQuery ?
- How to disable mouseout events triggered by child elements?
- How to make container shrink-to-fit child elements as they wrap?
- jQuery | Add Elements with Examples
- jQuery | Remove Elements
- How to select elements by attribute in jQuery ?
- How to Select a Range of Elements using jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.