Javascript DOM HTML Anchor hreflang Property set

Introduction

Change the language code of a link:

document.getElementById("myAnchor").hreflang = "fr";

Click the button to change the value of the hreflang attribute of the link to "fr".

View in separate window

<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" hreflang="en-us" href="https://www.java2s.com/">Examples</a></p>

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

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

<script>
function myFunction() {/*ww  w. j  ava2  s  .  co m*/
  document.getElementById("myAnchor").hreflang = "fr";
  document.getElementById("demo").innerHTML = "The hreflang value of the link changed.";
}
</script>

</body>
</html>



PreviousNext

Related