Y
yawnmoth
I'm trying to make a function that'll change the CSS class (className)
of an HTML element while preserving the old class. The problem is
that the old class can be one of any number of classes. As such, I
was wondering what the best way to go about saving the old className
is. I could do something like "element.oldClassName =
element.className; element.className = 'whatever';", but that would
kinda result in invalid (X)HTML. ie.
<img src="." alt="" class="whatever" /> is valid XHTML but <img
src="." alt="" oldclassname="whatever" /> isn't because the specs
don't define for an attribute called oldclassname for the img element.
So what other alternatives are out there? I could assign each element
a unique id and then associate the unique id to the old class name via
an object / associative array, but that seems excessive.
of an HTML element while preserving the old class. The problem is
that the old class can be one of any number of classes. As such, I
was wondering what the best way to go about saving the old className
is. I could do something like "element.oldClassName =
element.className; element.className = 'whatever';", but that would
kinda result in invalid (X)HTML. ie.
<img src="." alt="" class="whatever" /> is valid XHTML but <img
src="." alt="" oldclassname="whatever" /> isn't because the specs
don't define for an attribute called oldclassname for the img element.
So what other alternatives are out there? I could assign each element
a unique id and then associate the unique id to the old class name via
an object / associative array, but that seems excessive.