Cristian Cristian - 7 months ago 12
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

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
Comments