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.
- How to copy the content of a div into another div using jQuery ?
- How to iterate through all selected elements into an array ?
- How to overlay one div over another div using CSS
- How to center a div within another div?
- How to clear all div's content inside a parent div ?
- How to display div elements using Dropdown Menu in jQuery?
- What are the efficient ways to iterate over all DOM elements ?
- How to replace innerHTML of a div using jQuery?
- How to hide a div when the user clicks outside of it using jQuery?
- How to fadeOut and remove a div using jQuery ?
- How to animate div width and height on mouse hover using jQuery ?
- How to detect and change the content/style of a div using jQuery ?
- How to select a div with a certain class using jQuery ?
- How to dynamically set the height and width of a div element using jQuery ?
- How to show/hide div element depending multiple values using Bootstrap and jQuery ?
- How to count child element using jQuery ?
- How to remove parent element except its child element using jQuery ?
- Iterate associative array using foreach loop in PHP
- How to iterate over an Array using for loop in Golang?
- jQuery | Create a div element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.