Answers for "how to add text to element javascript"

2

how add text to element in javascript

var paragraph = document.getElementById("p");

paragraph.textContent += "This just got added";
Posted by: Guest on May-19-2021
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
0

how add text to element in javascript

document.getElementById("p").textContent += " this has just been added";
Posted by: Guest on May-19-2021
0

how to add text in javascript

<div id="mass">
<p id="ph1">This is a paragraph.</p>
<p id="ph2">This is another paragraph.</p>
</div>

<script>
var head = document.createElement("h1");
var node = document.createTextNode("New Heading.");
head.appendChild(node);

var ele = document.getElementById("mass");
var child = document.getElementById("ph1");
ele.insertBefore(head,child);
//ele.append(head,child);

Output : 
New Heading.
This is a paragraph.
This is another paragraph.
Posted by: Guest on March-18-2021

Code answers related to "how to add text to element javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language