Get the highest and lowest values of a certain attribute in jQuery or Javascript

前端 未结 7 1091
鱼传尺愫
鱼传尺愫 2020-12-10 05:37

I have the following divs:

test
test
7条回答
  •  温柔的废话
    2020-12-10 05:59

    var min = Number.MAX_VALUE, max = Number.MIN_VALUE;
    $(".maindiv").each(function () {
        var id = parseInt(this.id, 10);
        if (id > max) {
            max = id;
        }
        if (id < min) {
            min = id;
        }
    });
    

提交回复
热议问题