jQuery - How to match an element has attribute a or attribute b

后端 未结 3 431
無奈伤痛
無奈伤痛 2021-01-20 23:58

How to write a jquery selector to match an element has attribute a or attribute b. It must match three elements below


<         


        
相关标签:
3条回答
  • 2021-01-21 00:42

    You can use a multiple selector (,) with the attribute-equals selector (or any other selectors), for example:

    $("a[a=123], a[b=345]")
    

    You can test it out here.

    0 讨论(0)
  • 2021-01-21 01:00

    Try this

    $('a[b="345"],a[a=123] ')
    

    See the jQuery Multiple selector docs.

    0 讨论(0)
  • 2021-01-21 01:02

    Or generally for mere presence of attribute

    $("a[a], a[b]")
    
    0 讨论(0)
提交回复
热议问题