View Single Post
Old 11-29-2012, 01:59 AM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,449
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
That would overwrite any classnames already on the elements.

To keep the existing classes and add a new on simply add a space and the new class name to the end of the existing class list.

You should also use a regular expression to test for the class name with a boundary on either side in order to allow for it not being the only class in the class attribute.

See http://javascriptexample.net/dom04.php for the sort of loop you'd have using getElementsByClassName that also adds that method for browsers that don't already have it.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote