HEELPBOOK - How to change a CSS class style through Javascript? (HTML5) ################
Let's suppose you have:
text
...and the following styles:
.oldclass { color: blue } .newclass { background-color: yellow }
You can change the class on mydiv in javascript like this (using, for example, an onclick event-handler):
document.getElementById('mydiv').className = 'newclass';
After the DOM manipulation you will be left with:
text
If you want to add a new CSS class without removing the old one, you can append to it:
document.getElementById('mydiv').className += ' newClass';
This will result in:
text
############ ARTICLE INFO #############
Article Month: February
Article Date: 08/02/2013
Permalink: http://heelpbook.altervista.org/2013/how-to-change-a-css-class-style-through-javascript-html5/
Source: http://stackoverflow.com/questions/2221160/how-to-change-a-css-class-style-through-javascriptSource:
Language: English
View more articles on: http://www.heelpbook.net/
Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832
Follow us on Twitter: https://twitter.com/#!/HeelpBook
Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook
Follow us on Delicious: http://delicious.com/heelpbook
Linkedin: http://it.linkedin.com/pub/stefano-maggi/27/73a/b20
Google+ : https://plus.google.com/116990277568167008289/posts