What is the difference between innerText and outerText?

∥☆過路亽.° 提交于 2019-12-04 08:53:08

问题


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 !


回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/18481382/what-is-the-difference-between-innertext-and-outertext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!