Element innerHTML Property - Change the HTML content, URL, and target of a link: - Javascript DOM

Javascript examples for DOM:Element innerHTML

Description

Element innerHTML Property - Change the HTML content, URL, and target of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<button onclick="myFunction()">Change link</button>

<script>
function myFunction() {/*from w w w  .  j a v  a  2s  .  c  o m*/
    document.getElementById("myAnchor").innerHTML = "java2s.com";
    document.getElementById("myAnchor").href = "https://www.java2s.com";
    document.getElementById("myAnchor").target = "_blank";
}
</script>

</body>
</html>

Related Tutorials