Get elements by attribute when querySelectorAll is not available without using libraries?

后端 未结 8 743
半阙折子戏
半阙折子戏 2020-11-22 11:27

How can you do the equivalent to

document.querySelectorAll(\'[data-foo]\')

where query

8条回答
  •  囚心锁ツ
    2020-11-22 11:47

    That works too:

    document.querySelector([attribute="value"]);
    

    So:

    document.querySelector([data-foo="bar"]);
    

提交回复
热议问题