Code example to loop through div in jQuery.
In this code we will discuss about how we can loop html element bu jQuery. To loop html element by jQuery we will use each() function.
The each() function in jQuery allows us to loop any html elements. In the example below we created a html structure and and on these html code we have a parent div and there child div. We will loop each child element and will print there text in console. Similarly you can loop your html element and will get your desire value.
HTML
<div class="parent">
<div class="child">Html Code 1</div>
<div class="child">Html Code 2</div>
<div class="child">Html Code 3</div>
<div class="child">Html Code 4</div>
</div>
jQuery
$('.parent .child').each(function () {
console.log($(this).html()); //print html in console
});
Output
Html Code 1
Html Code 2
Html Code 3
Html Code 4
Thanks.