Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between innerText and outerText?

After searching through web i understood the difference between innerHTML and outerHTML.

However i am having hard time understanding the difference between innerText and outerText. Both appear almost same to me.

Can anyone help me understand this with a nice illustration ?

Thank You !

like image 445
Abhishek Singh Avatar asked Aug 28 '13 07:08

Abhishek Singh


2 Answers

innerText changes only text within HTML tags, e.g.

<div>   <p>Change Me</p> </div>  p.innerText = "Changed!" 

Becomes

<div>   <p>Changed!</p> </div> 

Whereas outerText:

<div>   <p>Change Me</p> </div>  p.outerText = "Changed!" 

Becomes

<div>    Changed! </div> 
like image 198
CodingIntrigue Avatar answered Sep 20 '22 16:09

CodingIntrigue


Basically,
innerText: what's between the tags of the element.
outerText: content of the element, including the tags.

like image 35
Sadiq Avatar answered Sep 23 '22 16:09

Sadiq