
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM insertAdjacentText( ) Method
The HTML DOM insertAdjacentText() method inserts text string at a specified position.
Syntax
Following is the syntax −
Calling insertAdjacentText() with parameters of positionString and text
node.insertAdjacentText(“positionString”, text)
Position Strings
Here, “positionString” can be the following −
positionString | Description |
---|---|
afterbegin | It inserts text after the beginning of node element |
afterend | It inserts text after the node element |
beforebegin | It inserts text before the node element |
beforeend | It inserts text before the end of node element |
Example
Let us see an example for InsertAdjacentText() method −
<!DOCTYPE html> <html> <head> <title>insertAdjacentText()</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>insertAdjacentText( )</legend> <h1>First Muslim President of India</h1> <h2 id="president">A.P.J Abdul Kalam</h2> <input type="button" onclick="rectifyName()" value="Correct Name"> </fieldset> </form> <script> function rectifyName() { var presidentH2 = document.getElementById("president"); presidentH2.insertAdjacentText("afterbegin", "DR. "); } </script> </body> </html>
Output
This will produce the following output −
Before clicking ‘Correct Name’ button −
After clicking ‘Correct Name’ button −
- Related Articles
- HTML DOM write() Method
- HTML DOM writeln() Method
- HTML DOM normalize( ) Method
- HTML DOM addEventListener() Method
- HTML DOM appendChild() Method
- HTML DOM blur() Method
- HTML DOM click() method
- HTML DOM cloneNode() method
- HTML DOM close() method
- HTML DOM compareDocumentPosition() Method
- HTML DOM console.assert() Method
- HTML DOM console.clear() Method
- HTML DOM console.count() Method
- HTML DOM console.error() Method
- HTML DOM console.group() Method

Advertisements