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

前端 未结 4 1619
鱼传尺愫
鱼传尺愫 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:01

    You can try this:

    $("div").each(function(i, elem){
     $(elem).append($(""+(i+1)+""));
    });
    

    JSFiddle example

提交回复
热议问题