Javascript DOM HTML Link hreflang Property set

Introduction

Change the language code of the linked document:

document.getElementById("myLink").hreflang = "en-us";

Click the button to change the language code of the linked document.

View in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" href="https://java2s.com" hreflang="ja">
</head>/*ww  w  . ja v  a  2 s  . co  m*/
<body>

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

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

<script>
function myFunction() {
  document.getElementById("myLink").hreflang = "en-us";
  document.getElementById("demo").innerHTML = "The language code was changed.";
}
</script>

</body>
</html>



PreviousNext

Related