77

I know that to filter an element with an atttribute called attrName which has value attrValue I do:

filter("[attrName='attrValue']")

but looking at the docs http://api.jquery.com/category/selectors/ I can't see an option to select all elements s.t. attrName>attrValue

Will this work

   filter("[attrName>'attrValue']")
4

4 に答える 4

113

You can do this using the function overload of .filter(), like this:

.filter(function() {
  return $(this).attr("attrName") > "someValue";
})
于 2010-04-10T14:14:38.787 に答える
29

注意してください。整数で遊んでいる場合は、を使用していることを確認してくださいparseInt()

$("selector").filter(function() {
    return parseInt($(this).attr("my-attr")) > 123;
});
于 2017-04-10T19:40:04.467 に答える
28

解決策はjQuery.filter()です:

$("selector").filter(function() {
    return  $(this).attr("my-attr") > 123;
});
于 2010-04-10T14:18:12.587 に答える
0

ES6矢印機能の場合

$("selector").filter((index, el) => {
    return parseInt($(el).attr("attrName")) > 123;
});
于 2021-03-05T06:31:26.010 に答える