Find all elements with a certain attribute value in jquery

后端 未结 5 1090
旧时难觅i
旧时难觅i 2020-12-02 11:16

I need to find all elements that has a special attribute value.

Here is the div I need to find (I have many of them..)

5条回答
  •  独厮守ぢ
    2020-12-02 11:43

    Although it doesn't precisely answer the question, I landed here when searching for a way to get the collection of elements (potentially different tag names) that simply had a given attribute name (without filtering by attribute value). I found that the following worked well for me:

    $("*[attr-name]")
    

    Hope that helps somebody who happens to land on this page looking for the same thing that I was :).

    Update: It appears that the asterisk is not required, i.e. based on some basic tests, the following seems to be equivalent to the above (thanks to Matt for pointing this out):

    $("[attr-name]")
    

提交回复
热议问题