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

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

I have the following divs:

test
test
7条回答
  •  一整个雨季
    2020-12-10 05:55

    You can use the sort function to do it.

    function arrayify(obj){
        return [].slice.call(null,obj);
    }
    var all = arrayify(document.querySelectorAll('div[id]'));
    var max = all.sort().pop();
    var min = all.sort().reverse().pop();
    

    This is way easier that using jQuery

提交回复
热议问题