This function mainly adds styles to the specified elements. Equivalent to addClass(class) in Jquery--add the specified class name to each matching element.
Required in Jquery class (String): One or more CSS class names to be added to the element, separated by spaces. And this function also has such requirements.
div{ border:1px solid #ccc; width:200px ; height:200px;}
.a{ background:#900; }
.b{ font-size:30px; font-weight:bold;}
function addClass(elements, value)
{
if ( !elements.className) {
elements.className = value;
}
else
{
newClass = elements.className;
newClass = " ";
newClass = value ;
elements.className = newClass;
}
}
window.onload = function ()
{
var test = document.getElementById('test');
alert(test.className);
addClass(test, 'a b');
//addClass(test, 'b');
}
This is the test layer
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