Answers for "javascript create a tag"

0

javascript create script tag

var script = document.createElement("script");
script.src = "https://url.com/";
document.head.appendChild(script);
Posted by: Guest on May-15-2020
11

how to add elements in javascript html

//adding 'p' tag to body

  var tag = document.createElement("p"); // <p></p>
  var text = document.createTextNode("TEST TEXT"); 
  tag.appendChild(text); // <p>TEST TEXT</p>
  var element = document.getElementsByTagName("body")[0];
  element.appendChild(tag); // <body> <p>TEST TEXT</p> </body>
Posted by: Guest on May-31-2020
-1

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>
Posted by: Guest on October-14-2020

Code answers related to "javascript create a tag"

Code answers related to "Javascript"

Browse Popular Code Answers by Language