Pedro Henrique Kuzminskas Pedro Henrique Kuzminskas - 8 months ago 66
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">


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.