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

Introduction

Using the "afterbegin" 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 .  java2  s .c  o m*/
  var h = document.getElementById("myH2");
  h.insertAdjacentText("afterbegin", "My inserted text");
}
</script>

</body>
</html>



PreviousNext

Related