Count All Div Elements And Add Each Number Inside Span Using Jquery
I need to show each number of div in the page in order And add the value of each div inside span so if I have 4 divs inside page like this
first div
Solution 1:
Simple each
loop does the trick:
$("div").each(function(i) {
$(this).find("span").text(++i);
});
Solution 2:
$("div").each(function(idx,elem) {
$("<span>").text(idx).appendTo(wherever);
});
Solution 3:
Solution 4:
var counter = 1;
$('h1').each(function () {
$(this).find('span').html(counter);
counter++;
});
Post a Comment for "Count All Div Elements And Add Each Number Inside Span Using Jquery"