Loop through all elements with class 'blah' and find the highest id value

前端 未结 4 2132
闹比i
闹比i 2021-02-13 20:25

I have a bunch of elements like:

..

I want to loop through all of them and get the highest

4条回答
  •  再見小時候
    2021-02-13 21:21

    I would do:

    var max = 0;
    $(".blah").each(function(){
        num = parseInt(this.id.split("-")[1],10);
        if(num > max)
        {
           max = num;
        }
    });
    

    Most people would do this way.

提交回复
热议问题