Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM insertAdjacentText() Method

  • Last Updated : 25 Jul, 2019

The insertAdjacentText() inserts a provided text at one of the following positions.

  • afterbegin:
  • afterend:
  • beforebegin:
  • beforeend:


node.insertAdjacentText(position, text)

Parameters: This method requires 2 parameters.

  • position: A position relative to the element.The legal values are:
    1. afterbegin: Just inside the element, before its first child.
    2. afterend: After the element itself.
    3. beforebegin: Before the element itself.
    4. beforeend: Just inside the element, after its last child.
  • text: The text you want to insert.

Return Value: No Return Value.

Exceptions: If the specified position is not recognized.


<!DOCTYPE html>
        HTML | DOM insertAdjacentText() Method
    <!--script to insert specified 
           element to specified position-->
        function insadjtxt() {
            var h = document.getElementById("m1");
                " Computer Science Portal.");
    <h1> Welcome To GeeksforGeeks</h1>
      <p id="m1">GeeksforGeeks is a </p>
      Click the button to insert some
      text after the sentence:
    <button onclick="insadjtxt()">
        Insert text


Before clicking insert text button:

After clicking insert text button:

Supported Browsers: The browser supported by DOM insertAdjacentText() Method are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Apple Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!