Home >Web Front-end >JS Tutorial >Analysis of disadvantages of dynamically modifying the id attribute in DOM_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 19:01:341061browse

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.

Statement:
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