jQuery: How to select all elements which have an attribute that is not equal to specific value?

前端 未结 1 906
慢半拍i
慢半拍i 2021-01-02 23:54

How could I select in jQuery all elements that have the my_attr attribute which is not equal to my_value ?

If my_attr is

相关标签:
1条回答
  • 2021-01-03 00:32

    To get a "doesn't match", you'd use an attribute not-equals selector with (the other part of the question) as has-attribute selector, like this:

    $("span[a][a!='4']")
    

    If you want it to equal, just take out the ! for an attribute-equals selector, like this:

    $("span[a][a='5']")
    

    To use a variable, just concatenate, like this:

    $("span[" + my_attr + "][" + my_attr + "!='" + my_value + "']")
    
    0 讨论(0)
提交回复
热议问题