Getting element by a custom attribute using JavaScript

前端 未结 7 1108
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 05:24

I have an XHTML page where each HTML element has a unique custom attribute, like this:

<
7条回答
  •  失恋的感觉
    2020-11-30 06:03

    document.querySelector("div[data-automation]")

    => finds the div

    document.querySelector("div[data-automation='something']")
    

    => finds the div with a value

提交回复
热议问题