Today in the use of innertext encountered a compatibility problem, Firefox does not support InnerText method, check the next mdn, found that Firefox has a similar method, called textcontent, it and IE innertext similar, Is the method used to get (set) the text in the element.
Grammar
• Set up
Copy Code code as follows:
element.textcontent = "text";
• Get
Copy Code code as follows:
var text = element.textcontent;
Copy Code code as follows:
Note: textcontent is similar to innertext and also gets the text content of the child elements, such as
<div>this is <span>a</span> text!</div>
Div.textcontent = = "This is a text!"
the difference between the innertext and the
Textcontent Gets the content of all elements, including ' <script> ' and ' <style> ' elements
InnerText does not get the content of the hidden element, and Textcontent does not
innertext will trigger Reflow, and textcontent will not
The innertext return value is formatted, and Textcontent does not
Mainstream browser support situation
IE 9+
Chrome 1+
Firefox (Gecko)