Attribute specified Property - Javascript DOM

Javascript examples for DOM:Attribute

Description

The specified property returns true if the attribute is specified or created not attached yet.

Otherwise it returns false.

Return Value

A Boolean, returns true if the attribute is specified, otherwise false

The following code shows how to Find out if an attribute has been specified or not:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from  ww w  .  java 2  s . c o  m*/
    var btn = document.getElementsByTagName("BUTTON")[0];
    var x = btn.getAttributeNode("onclick").specified;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials