Cristian Cristian - 2 years ago 113
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download