Pedro Henrique Kuzminskas Pedro Henrique Kuzminskas - 1 year ago 91
Javascript Question

Get the div by the data-checked

I need to get the div when it presents the value of "no" in the data-checked.

how can I do this in JavaScript?

<div class="checkbox quote-form-element" data-checked="yes" data-name="PolĂ­tica de Privacidade">

Answer Source

Try using an Attribute Selector(docs: jQuery, MDN):



document.querySelector('div[data-checked="no"]') // get just one element
document.querySelectorAll('div[data-checked="no"]') // get a collection of elements

Working demo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download