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

前端 未结 4 2129
闹比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:25

    I'd go for this, using .map, .get and .sort:

    $('.blah').map(function(){
        return parseInt(this.id.split('-')[1], 10);
    }).get().sort(function(a, b) {
        return b - a;
    })[0];
    

提交回复
热议问题