
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM Element outerText Property
The HTML DOM Element outerText property is used to set (update) and get (retrieve) the text content of an HTML element, including all its nested text and elements.
This property is similar to the textContent property, but there are some differences between them as follows:
- Both properties get and set the content of an element.
- The outerText property replaces the element itself when setting the content.
- The textContent property does not replace the element; it only updates the content within the element.
Syntax
Following is the syntax of the HTML DOM Element outerText (to set the property) −
node.outerText = text;
Here, text is the new content that you want to set.
Use the following syntax to get the outerText property −
node.outerText;
Parameters
Since this is the property, it will not accept any parameter.
Return Value
This property returns a string containing the combined text of an element and all its nested text and elements when accessed.
Example 1: Retrieving the Current Text of DIV
The following is the basic example of the HTML DOM Element outerText property. It retrieves the current text (content) of the <div> element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element outerText</title> </head> <body> <h3>HTML DOM Element outerText Property</h3> <p>Click button to retrieve current text of div.</p> <div id="demo">Hey!, this is inside div</div><br> <button onclick="retrieveText()">Change Text</button> <p id="res"></p> <script> function retrieveText() { var div_ele = document.getElementById('demo'); document.getElementById("res").innerHTML = div_ele.outerText; } </script> </body> </html>
The above program displays the current content (text) of the "div" element.
Example 2: Setting the Content of Paragraph (p) Element
Following is another example of the HTML DOM Element outerText property. We use this property to set the content of a <p> element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element outerText</title> </head> <body> <h3>HTML DOM Element outerText Property</h3> <p>Click button to set text of p element.</p> <p id="demo"></p> <button onclick="retrieveText()">Set Content</button> <script> function retrieveText() { var p_ele = document.getElementById('demo'); p_ele.outerText = "This is the new text"; } </script> </body> </html>
After executing the above program, a new content will be set of a p element when the button is clicked.
Example 3: Updating the Existing Content
In the example below, we use this property to update (set) the old content of <li> element with new one −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element outerText</title> </head> <body> <h3>HTML DOM Element outerText Property</h3> <p>Click button to update "List item1" content.</p> <ul> <li id="demo">List item1</li> <li>List item2</li> <li>List item3</li> <li>List item4</li> </ul> <button onclick="retrieveText()">Update Content</button> <script> function retrieveText() { var p_ele = document.getElementById('demo'); p_ele.outerText = "List item updated!"; } </script> </body> </html>
The above program updates the existing content with new one "List item updated!".
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
outerText | Yes | Yes | Yes | Yes | Yes |