Sharing of compatibility tips for DOM operations_DOM
For example: when we get all li elements under ul. Or when it is the next element of an element. You may encounter this annoying space problem. Of course, these spaces will be automatically filtered in IE browser. FF, on the other hand, is not that hard-working. FF browser will treat these spaces as an element. If you are confused about space elements in the Dom, please run the following code. Use at least two browsers, IE and FF, to test. You will understand everything!
After running this code. You will find that 3. pops up in IE. Pop up in FF7.
- html
- css
- dom< ;/li>
<script> <br>var list = document.getElementById("list"); <br>var list_child = list.childNodes; //Get all in ol The child elements of <br>alert("There are "list_child.length" elements in ol, respectively"); <br>for(var i = 0; i<list_child.length; i ){ <BR>alert(list_child [i].tagName); <BR>} <BR></script>
The above code demonstrates the need Get all child elements in the ol element. And pop up several sub-elements in ol. We can see that ol contains 3 li elements. 3 pops up in IE. This is correct. So why does 7 pop up in FF and Chrome browsers? In fact, when you write code. A space will be formed between the element and the element wrap. (Note: Don’t think that a space will be formed by entering a carriage return. This is wrong. That is to say, the space between elements means that you just change the line hundreds of times. It is also counted as a space) FF and Chrome browsers will not Filter these space elements. So popping up 7 is also correct.
We use the same html structure below. To demonstrate how to filter and remove these space elements.
head>
After running this code. You will find that the results returned in IE, FF, and Chrome are the same.
- html
- css
- dom< ;/li>
<script> <br>function Del_space(elem){ //Function to filter spaces <br>var elem_child = elem.childNodes; //Get all child elements <br>for(var i = 0;i<elem_child.length;i ){ <BR>//If it is a text node and the content only contains spaces, delete the node <BR>if(elem_child[i].nodeName = = "#text" && ! /S/.test(elem_child[i].nodeValue)){ <BR>elem.removeChild(elem_child[i]);//If the element is a space, delete it <BR>} <BR>} <BR>} <BR>Del_space(document.getElementById("list")); //Delete all spaces in ol <BR>var list = document.getElementById("list"); <BR>var list_child = list.childNodes; //Get all child elements in ol <BR>for(var i=0;i<list_child.length;i ){ <BR>alert(list_child[i].tagName); <BR>} <BR></script>
The following method is recommended:
After running this code. You will find that the results returned in IE, FF, and Chrome are the same.
- html
- css
- dom< ;/li>
<script> <br>for(var x=0,list_li = document.getElementById('list').childNodes; x<list_li.length; x ) { <BR>if(list_li[x].nodeType == 1){ <BR>alert(list_li[x].tagName); <BR>} <BR>} <BR></script>
< ;/body>

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will encounter freezes or blue screens when operating the computer. At this time, we need to find the most stable win10 version to operate. Overall, it is very easy to use and can make your daily use smoother. The most stable win10 version in history 1. Win10 genuine original system. Here users can use simple operations. The system has been optimized and has strong stability, security and compatibility. Users can follow the steps to achieve the perfect machine. 2. Russian master streamlined The version of win10 has been strictly streamlined and many unnecessary functions and services have been deleted. After streamlining, the system has lower CPU and memory usage and runs faster. 3. Win10 Lite Edition 1909 is installed on multiple computers with different hardware models.

Switch2 is a new model announced by Nintendo at Gamescom 2023. Some players are worried about whether there will be compatibility issues between the new model and the cartridges of previous versions. Let’s take a look. Is switch2 compatible with switch cassette? Answer: switch2 is not compatible with switch cassette. Introduction of Switch 2 cartridges According to information from Nintendo’s production chain company, Switch 2 may use 64GB cartridges. Because it has better performance and supports more 3A game masterpieces, it requires a larger cartridge capacity. Because many game works need to be castrated and compressed before they can be stuffed into a game cartridge. Moreover, Switch cartridges are prone to copying game content, so replace them with new cartridges.

As we all know, a major feature of win11 is its own Android subsystem, which allows us to install Android software without using an emulator. However, there is also the problem of win11 Android application lag. How should this be solved? Is win11 not compatible with dynamic wallpapers? Answer: Win11 is compatible with dynamic wallpapers. If it cannot be used, it may be because the software or system version is lagging behind. If it was just updated, it may be covered by the system wallpaper. 1. If the system or software version is lagging behind, just update the system and dynamic wallpaper software. 2. If it is covered by the system wallpaper, you can try to open "Settings" 3. Then enter the "Background" settings under "Personalization". 4. Then change the personalized background to "Picture" 5. After the modification is completed, you can set the dynamic wallpaper normally

In recent years, the popularity of the Android system in the field of mobile devices has grown rapidly, and many people have begun to pay attention to whether Android applications can also be run on other platforms. As a common operating system, Linux is favored by many people. So the question is, is the Linux system compatible with Android software? The first thing to make clear is that the Linux system and the Android system have certain similarities in the kernel. They are both operating systems based on the Linux kernel. Therefore, theoretically speaking, the Linux system can run

How to resolve d3dx9_43.dll incompatibility. In recent years, the rapid development of computers and games has allowed us to enjoy more entertainment and convenience. However, sometimes when installing or running certain programs, we may encounter some error messages, such as "d3dx9_43.dll is incompatible". In this case, how should we solve this problem? First, let’s understand what this error message means. d3dx9_43.dll is a system file of DirectX, which is used in the operating system

The reason why many friends are still choosing win7 system instead of win10 system is that they are afraid of poor compatibility. In fact, win10 system can now set the compatibility mode of win7. You only need to change the settings in the properties. Let’s take a look at it together. How to make win10 compatible with win71? First, right-click on the program we need to run under win7 system, then open "Properties" 2, then click "Compatibility" above to enter the compatibility tab. 3. Check "Run this program in compatibility mode" in compatibility mode. 4. Then select "Windows 7" from the drop-down menu below. 5. After finishing, just click "Apply" or click "OK".

What should I do if I encounter an incompatible version of Eclipse? [Introduction] As a popular development tool, Eclipse not only provides powerful functions and rich plug-ins, but also has cross-platform features. However, when using Eclipse, you may sometimes encounter version incompatibility issues, which may cause the program to fail to run properly or compile errors. This article will describe how to deal with Eclipse version incompatibility and provide some code examples to solve common compatibility issues. [Solution] Update Ecl

There are many website users who need to use the old version of the browser when browsing, and the new version needs to add compatible outlets before they can be used, so today I will bring you a detailed tutorial on adding compatible outlets in win11. Come and learn. How to add compatible outlets in win11 1. First open the IE browser in the system, click the small gear in the upper right corner of the browser to enter "Settings". 2. Then in the settings menu that opens, open "Compatibility View Settings". 3. Enter the URL to be added in the edit box under Add this website, and then click "Add". 4. Finally, you can see the domain name of the added URL below, and you can access it directly by closing the window.
