create a tag javascript code example

Example 1: javascript create script tag

var script = document.createElement("script");
script.src = "https://url.com/";
document.head.appendChild(script);

Example 2: create a link javascript

<html>
  <head></head>
  <body>
    <script>
      var a = document.createElement('a');
      var linkText = document.createTextNode("my title text");
      a.appendChild(linkText);
      a.title = "my title text";
      a.href = "http://example.com";
      document.body.appendChild(a);
    </script>
  </body>
</html>