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
You can try this:
$("div").each(function(i, elem){
$(elem).append($("<span>"+(i+1)+"</span>"));
});
JSFiddle example
$("div").each(function(idx,elem) {
$("<span>").text(idx).appendTo(wherever);
});
var counter = 1;
$('h1').each(function () {
$(this).find('span').html(counter);
counter++;
});
jsFiddle example
Simple each
loop does the trick:
$("div").each(function(i) {
$(this).find("span").text(++i);
});
Demo: http://jsfiddle.net/CtDLe/3/