Home > Web Front-end > JS Tutorial > Comparison and usage introduction of innerText and textContent_javascript skills

Comparison and usage introduction of innerText and textContent_javascript skills

WBOY
Release: 2016-05-16 17:41:22
Original
1125 people have browsed it

Today I encountered a compatibility issue when using innerText. FireFox does not support the innerText method. I checked MDN and found that there is a similar method under FireFox called textContent. It is similar to IE's innerText and is used to obtain (set) The method of text in the element.

Syntax
•Settings

Copy code The code is as follows:

element.textContent = "text";

• Get
Copy code The code is as follows:

var text = element.textContent;

Copy code The code is as follows:

Note: textContent is similar to innerText, and will also obtain the text content of child elements at the same time, such as
this is text!

// div.textContent == "this is a text!"

Differences from innerText
•textContent will get the content of all elements, including `
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template