


There is an innerText attribute under IE and a textContent attribute under FF. Many people who used to write scripts for IE could not find the innerText attribute under FF, so the suggestion found on the Internet was to use textContent instead. The same goes for those who write scripts for FF.
But actually, there is a misunderstanding here. Many articles on the Internet say that "the attribute equivalent to the innerText attribute under FF is textContent" - but in fact this is not the case. There are several important differences between innerText and textContent, which prevents them from being used directly interchangeably in some cases.
I wrote a code highlighting JS plug-in a few days ago. It works perfectly under IE, but not properly under FF. Under IE, the innerText attribute is used, while under FF, the textContent attribute is used. The difference between the two leads to completely different results when processing strings. So I wrote something specifically to test the difference between the two.
According to the test results:
innerText: Its content is actually what you see in the browser. Its value is the result of interpretation by the browser: it escapes, interprets, and finally displays the innerHTML of the element, and then removes the plain text left behind by various formatting information. It will replace
with a newline character, and will treat multiple spaces into one space. However, the original newline character will not cause a newline, and IE will treat it as an ordinary word boundary (generally is a space). To put it more graphically, the value of the innerText attribute of an element is consistent with the content when you copy and paste the content of this element into Notepad.
textContent: Its content is the content of innerHTML after removing all tags (I suspect this is an attribute copied from XMLDOM, and the characteristics are exactly the same). It will escape the escape characters ( will not cause newline).
A more concise summary: innerText in IE requires the value of innerHTML:
1. HTML escaping (equivalent to XML escaping, processing escape characters such as 2. After HTML interpretation and CSS style interpretation;
3. Then the plain text left after removing the format information
.
The textContent in FF does not have steps 2 and 3. After HTML escaping, all html tags are directly removed and the resulting plain text is obtained.
An example:
This div with the ID of T1,
The value of the innerText attribute in IE is:
Copy code
And the value of the textContent attribute in FF Copy the code for:
Note that there is a div nested in that div, and this better reflects the difference in the processing methods of IE's innerText and FF's textContent:
div is a block element and will occupy one line by default, so , the innerText in IE reflects that the RS in the above div occupies an exclusive line, while FF's textContent completely ignores the HTML format, so the RS in its textContent is connected with other characters and does not occupy an exclusive line.
If you want to go further, take a look at this interesting result:
If you add a style="float:left;" to the div inside, then the div will change from a block element to a row element. No longer occupies an exclusive line, so the RS in IE's innerText attribute no longer occupies an exclusive line, but is connected with other characters. In FF, since textContent ignores labels and does not care about CSS, the value of its textContent attribute will not any changes.
It seems that many online talks about "let FF support the innerText attribute" are actually more or less problematic. Implementing IE's innerText is far from as simple as imagined. If you want to use JavaScript to make FF have exactly the same effect as innerText, you have to parse all the html tag attributes yourself, explain them, and even need to explain the css...
(However, according to the principle, it seems that the innerText effect can be simulated under FF through the copy and retrieval operations of the clipboard (this has not been tested), but 1 has side effects, and the clipboard operation under 2FF is also very troublesome.)
But fortunately, most of the time we don’t need to be so precise. We can achieve a closer effect by using innerHTML to do some simple processing.
Note: The above code was tested under IE6 and FF3.

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

10 fun jQuery game plugins to make your website more attractive and enhance user stickiness! While Flash is still the best software for developing casual web games, jQuery can also create surprising effects, and while not comparable to pure action Flash games, in some cases you can also have unexpected fun in your browser. jQuery tic toe game The "Hello world" of game programming now has a jQuery version. Source code jQuery Crazy Word Composition Game This is a fill-in-the-blank game, and it can produce some weird results due to not knowing the context of the word. Source code jQuery mine sweeping game

This tutorial demonstrates how to create a captivating parallax background effect using jQuery. We'll build a header banner with layered images that create a stunning visual depth. The updated plugin works with jQuery 1.6.4 and later. Download the

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

This article demonstrates how to automatically refresh a div's content every 5 seconds using jQuery and AJAX. The example fetches and displays the latest blog posts from an RSS feed, along with the last refresh timestamp. A loading image is optiona

Matter.js is a 2D rigid body physics engine written in JavaScript. This library can help you easily simulate 2D physics in your browser. It provides many features, such as the ability to create rigid bodies and assign physical properties such as mass, area, or density. You can also simulate different types of collisions and forces, such as gravity friction. Matter.js supports all mainstream browsers. Additionally, it is suitable for mobile devices as it detects touches and is responsive. All of these features make it worth your time to learn how to use the engine, as this makes it easy to create a physics-based 2D game or simulation. In this tutorial, I will cover the basics of this library, including its installation and usage, and provide a


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools