HTML | DOM insertAdjacentText() Method
The insertAdjacentText() inserts a provided text at one of the following positions.
- afterbegin:
- afterend:
- beforebegin:
- beforeend:
Syntax:
node.insertAdjacentText(position, text)
Parameters: This method requires 2 parameters.
- position: A position relative to the element.The legal values are:
- afterbegin: Just inside the element, before its first child.
- afterend: After the element itself.
- beforebegin: Before the element itself.
- 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.
Example:
<!DOCTYPE html> <html> <head> <title> HTML | DOM insertAdjacentText() Method </title> <!--script to insert specified element to specified position--> <script> function insadjtxt() { var h = document.getElementById("m1"); h.insertAdjacentText("beforeend", " Computer Science Portal."); } </script> </head> <body> <h1> Welcome To GeeksforGeeks</h1> <strong> <p id="m1">GeeksforGeeks is a </p> </strong> <p> Click the button to insert some text after the sentence: </p> <button onclick="insadjtxt()"> Insert text </button> </body> </html> |
Output:
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
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM normalizeDocument() Method
- HTML | DOM History go() Method
- HTML | DOM importNode() Method
- HTML | DOM removeAttributeNode() Method
- HTML | DOM hasChildNodes() Method
- HTML | method Attribute
- HTML | DOM cloneNode() Method
- HTML | DOM write() Method
- HTML | DOM exitFullscreen() Method
- HTML | DOM console.log() Method
- HTML | DOM appendChild() Method
- HTML | DOM isEqualNode() Method
- HTML | DOM createTextNode() Method
- HTML | DOM fullscreenEnabled() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



