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

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

    var counter = 1;
    $('h1').each(function () {
        $(this).find('span').html(counter);
        counter++;
    });
    

    jsFiddle example

提交回复
热议问题