JavaScript
Article
By Sam Deering

jQuery innerText() vs outerText()

By Sam Deering
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

jQuery InnerText() vs jQuery OuterText()

jQuery Innertext() and OuterText() functions are almost identical. Note that these can be referred to as jQuery functions but they are actually JavaScript properties. For arguments sake we will use jQuery! :)

The jQuery InnerText() property replaces the content between the opening and closing tags of an element with the specified text while the OuterText() property removes an element and inserts the specified text in place of it.

Things to remember:

* InnerText just replaces the content inside the tags
* Outertext replaces the content and the enclosing tags themselves

--ADVERTISEMENT--

jQuery innerText() Function Examples

//simple example to change the text of a page element
document.getElementById("elementID").innerText = "I love jQuery4u Blog!";

Here's the text that will change.

Demo

jQuery outerText() Function Examples

document.getElementById("elementID").outerText = "I love jQuery4u Blog!"



Yes, I <3 jQuery .

Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the latest in JavaScript, once a week, for free.