Example HTML:
<div id="foo" class="class_one"></div>
How can I add the class class_two without replacing class_one?
class_two
class_one
end result:
<div id="foo" class="class_one class_two"></div>
See deekshith's answer below if you only need to support new browsers
Standard javascript:
document.getElementById('foo').className += ' class_two'
or JQuery:
$('#foo').addClass('class_two');
1.4m articles
1.4m replys
5 comments
57.0k users