jared jared - 1 year ago 84
CSS Question

Add a class to a DIV with javascript

Example HTML:

<div id="foo" class="class_one"></div>

How can I add the class
without replacing

end result:

<div id="foo" class="class_one class_two"></div>

Answer Source

Standard javascript:

document.getElementById('foo').className += ' class_two'

or JQuery:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download