Nice programing

jQuery : 속성이 값보다 큰 모든 요소 선택

nicepro 2020. 11. 23. 20:01
반응형

jQuery : 속성이 값보다 큰 모든 요소 선택


attrValue 값을 가진 attrName이라는 속성으로 요소를 필터링하는 것을 알고 있습니다.

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

하지만 http://api.jquery.com/category/selectors/ 문서를 보면 st attrName> attrValue 모든 요소를 ​​선택하는 옵션을 볼 수 없습니다

작동할까요

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

다음 .filter()과 같이 의 함수 오버로드를 사용하여이를 수행 할 수 있습니다 .

.filter(function() {
  return $(this).attr("attrName") > "someValue";
})

해결책은 jQuery.filter ()입니다 .

$("selector").filter(function() {
    return  $(this).attr("my-attr") > 123;
});

정수를 가지고 노는 경우를 사용하고 있는지 확인하십시오 parseInt().

$("selector").filter(function() {
    return parseInt($(this).attr("my-attr")) > 123;
});

참고 URL : https://stackoverflow.com/questions/2613648/jquery-selecting-all-elements-where-attribute-is-greater-than-a-value

반응형