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

Analysis of disadvantages of dynamically modifying the id attribute in DOM_javascript skills

WBOY
Release: 2016-05-16 19:01:34
Original
1047 people have browsed it

In IE, modifying the id attribute has no non-standard impact on future DOM operations. You can still find the element through document.getElementById(), but there will be problems with CSS support. The id will not be automatically removed after modification. Re-match CSS rules, so the id will not reflect the proper style after modification.

Therefore, you should avoid modifying the id attribute when doing DOM programming. If you need to dynamically change the matching CSS rules, change the class attribute. When I encountered this problem, I tried to modify the only element that matched a certain CSS filter by modifying the id attribute. It turned out that there was no modification at all in IE after the modification, and then I changed to the class attribute to achieve the same purpose.

Related labels:
id
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