Count all div elements and add each number inside span using jQuery

前端 未结 4 1625
鱼传尺愫
鱼传尺愫 2021-02-10 02:45

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



        
4条回答
  •  情话喂你
    2021-02-10 03:11

    Simple each loop does the trick:

    $("div").each(function(i) {
        $(this).find("span").text(++i);
    });
    

    Demo: http://jsfiddle.net/CtDLe/3/

提交回复
热议问题