1. el.setAttribute('class','abc');
setAttribute('class', 'abc')
test div
<script> <BR>var div = document.getElementById('d1'); <BR>div.setAttribute("class", "abc"); <BR></script>
IE6/7: The background color of the div is not red
IE8/9/10/Firefox/Safari/Chrome/Opera: The background color of the div is red
Result: IE6/ 7 does not support the setAttribute('class',xxx) method to set the class of an element.
2. el.setAttribute('className', 'abc')
setAttribute('className', 'abc') test div
<script> <BR>var div = document.getElementById('d1'); <BR>div.setAttribute("className", "abc"); <BR></script>
IE6/7: The background color of the div is red
IE8/9/10/Firefox/Safari/Chrome/Opera: The background color of the div is not red
Result: IE8/9/10/Firefox/Safari/Chrome/Opera does not support the setAttribute('className',xxx) method to set the class of an element.
It’s interesting that when using setAttribute, the first parameters are class and className. The situation is exactly the opposite in IE6/7 and IE8/9/10/Firefox/Safari/Chrome/Opera.
3. el.className = 'abc';
el.className = 'abc'
<script> <BR>var div = document .getElementById('d1'); <BR>div.className = 'abc'; <BR></script>
Supported by all browsers.
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