Use jQuery to select multiple elements with .eq()

后端 未结 4 1984
南旧
南旧 2020-12-28 19:46

I want to select a subset of tds from a table.

I know before hand what the indexes are, but they are effectively random (not odd or even indexes, etc).

For i

4条回答
  •  失恋的感觉
    2020-12-28 20:33

    I wrapped VisioN's filter method into a jQuery plugin:

    $.fn.eqAnyOf = function (arrayOfIndexes) {
        return this.filter(function(i) {
            return $.inArray(i, arrayOfIndexes) > -1;
        });
    };
    

    So now usage is nice and clean:

    var $tds = $('table td').eqAnyOf([1, 5, 9]);
    

提交回复
热议问题