Home > Web Front-end > JS Tutorial > body text

Javascript code to obtain the text value of a node that is compatible with IE and Firefox_javascript skills

WBOY
Release: 2016-05-16 18:40:16
Original
1019 people have browsed it

We know that the value of the string contained in the node can be obtained through the innerHTML attribute that comes with the browser. For example, the following nodes:

Copy code The code is as follows:

i'm strong


Copy the code via
The code is as follows:

var obj=document.getElementById("test" );alert(obj.innerHTML);//The returned value is i'm strong

If I want to get the text value of the node, the label will not be included. string, what should I do? The text value here is: i'm strong
//Non-Mozilla browser: obj.innerText;//Other browsers obj.firstChild.nodeValue;
First provide a general method to solve compatibility issues:
The complete code is as follows:
Code

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]
Let FireFox support The implementation code of innerText
Please indicate the source for reprinting: http://www.cnblogs.com/wbkt2t/
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template