Could anyone let me know how to remove a class on an element using JavaScript only? Please do not give me an answer with jQuery as I can't use it, and I don't know anything about it.
You could simply set the elements class to nothing.
or if you wanted to keep a particular class you could just reset the class
| |||||||||||||||||||||
|
where | |||||||||||||||||||||
|
Here's a way to bake this functionality right into all DOM elements:
| |||||||||||||
|
Actually, the right way (standard) to do (but only works with Firefox3.6):
I'm going to publish an article about that on http://hacks.mozilla.org next week with fallback mechanism for other browsers. Documentation: https://developer.mozilla.org/en/DOM/element.classList | |||||||||||||||||||||
|
try:
| |||
|
Check this out: http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript This answer has some good examples. Patrick. | |||
|
More at https://developer.mozilla.org/en-US/docs/Web/API/element.classList | |||
|
It's very simple, I think.
| |||||||||
|
All of these answers are way too complicated, try
The result would be a return of the string
Super easy. Credits go to jondavidjohn Remove portion of string in Javascript | |||||
|
I was just working with something like this. Here's a solution I came up with...
Now you can call or chain it: | |||||||||
|
There is also Take a look at this jsFiddle example to see it in action. | |||||||||
|