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');
2.1m questions
2.1m answers
60 comments
57.0k users