add an anchor tag onclick
snippet in html

add an anchor tag onclick

user9367

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  var x = document.createElement("A");
  var t = document.createTextNode("Tutorials");
  x.setAttribute("href", "https://www.w3schools.com");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>