Element setAttributeNode() Method - Set the href attribute node of a <a> element: - Javascript DOM

Javascript examples for DOM:Element setAttributeNode

Description

Element setAttributeNode() Method - Set the href attribute node of a <a> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myAnchor">A Link: go to java2s.com</a>

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

<script>
function myFunction() {/*from   w ww.ja  va 2s .  c  om*/
    var anchor = document.getElementById("myAnchor");
    var att = document.createAttribute("href");
    att.value = "http://www.java2s.com";
    anchor.setAttributeNode(att);
}
</script>

</body>
</html>

Related Tutorials