Cristian Cristian - 1 year ago 43
Javascript Question

Check dom element if it has property

I have this element:

<div class="column" style="background: green;" used="used"></div>

How can I check if the div has the 'used' property = 'used'?

I am asking how to do this in javascript not in jQuery.


You can check it by using getAttribute(attributeName) function,

var elem = document.querySelector(".colum[user]");
var hasUsed = elem.getAttribute("used") == "used";

console.log(hasUsed); //  true/false