Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  12] [ 7]  / answers: 1 / hits: 112063  / 12 Years ago, thu, july 12, 2012, 12:00:00

Example HTML:



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


How can I add the class class_two without replacing class_one?



end result:



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

More From » html

 Answers
5

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');

[#84317] Tuesday, July 10, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mary

Total Points: 432
Total Questions: 98
Total Answers: 98

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;