Pedro Henrique Kuzminskas Pedro Henrique Kuzminskas - 2 months ago 14
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

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

$('div[data-checked="no"]')

Or:

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

Working demo.

Comments