Javascript DOM HTML Element insertAdjacentText() Method with beforeend as position

Introduction

Using the "beforeend" value:

Click the button to insert some text inside the header:

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>This method inserts a specified text, into a specified position.</p>

<h2 id="myH2">My Header</h2>
<button onclick="myFunction()">Insert text</button>

<script>
function myFunction() {//from  w w w  .  ja  va 2 s .  c  o m
  var h = document.getElementById("myH2");
  h.insertAdjacentText("afterend", "My inserted text");
}
</script>

</body>
</html>



PreviousNext

Related