Answers for "HTML DOM insertAdjacentText() Method"

0

HTML DOM insertAdjacentText() Method

<!DOCTYPE html>
<html>
<body>

<h1>HTML DOM insertAdjacentText() Method</h1>

<p>This method inserts a specified text, into a specified position.</p>

<h2 id="myH2">My Header</h2>

<p>Click the button to insert some text after the header:</p>

<button onclick="myFunction()">Insert text</button>

<script>
function myFunction() {
  var h = document.getElementById("myH2");
  h.insertAdjacentText("afterend", "My inserted text");
}
</script>

</body>
</html>
Posted by: Guest on February-28-2021

Browse Popular Code Answers by Language