Javascript Reference - HTML DOM specified Property








The specified property returns true if the attribute is specified.

Browser Support

specified Yes Yes Yes Yes Yes

Syntax

var v = attribute.specified

Return Value

A Boolean, true|false, to tell if an attribute has been set.





Example

The following code shows how to find out if an attribute has been set or not.


<!DOCTYPE html>
<html>
<body>
<!--  w  w  w  .  j a v  a2 s . com-->
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var btn = document.getElementsByTagName("BUTTON")[0];
    var x = document.getElementById("demo");
    x.innerHTML = btn.getAttributeNode("onclick").specified;
}
</script>

</body>
</html>

The code above is rendered as follows: