Element getAttribute() Method - Get the value of the target attribute of an <a> element: - Javascript DOM

Javascript examples for DOM:Element getAttribute

Description

Element getAttribute() Method - Get the value of the target attribute of an <a> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {// w  w w. j  av a2s . co  m
    var elmnt = document.getElementById("myBtn");
    var attr = elmnt.getAttributeNode("onclick").value;
    document.getElementById("demo").innerHTML = attr;
}
</script>

</body>
</html>

Related Tutorials