Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > restore original className

Reply
Thread Tools

restore original className

 
 
bmgz
Guest
Posts: n/a
 
      06-22-2005
I have written a script that highlights a table row when the appropriate
checkbox is checked. Using element.style is a bit messy and doesn't
really fulfil my needs..

I want to just be able to use className, but when I uncheck a row I am
having difficulty restoring the original (when the page loaded)
className, I need to do this because the rows have different styles

Is their any other way to access the original className of an element?
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-22-2005


bmgz wrote:


> I want to just be able to use className, but when I uncheck a row I am
> having difficulty restoring the original (when the page loaded)
> className, I need to do this because the rows have different styles
>
> Is their any other way to access the original className of an element?


I don't think so, once you manipulate className the initial value is
gone so you need to store it before changing it and restore it back when
needed e.g.
function setClassName (element, className) {
element.previousClassName = element.className;
element.className = className;
}

function unsetClassName (element) {
if (typeof element.previousClassName == 'string') {
element.className = element.previousClassName;
}
}


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Matt Kruse
Guest
Posts: n/a
 
      06-22-2005
bmgz wrote:
> Is their any other way to access the original className of an element?


If your original class is:

class="myClass"

Then when you set your new class you can do:

..className = .className + " myHighlightedClass";

When you unhighlight, chop off the extra class.

Btw, setting className directly is sometimes not a good idea, because an
object may have several classes. Setting it explicitly destroys any other
classes it might have.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to restore the original perspective in eclipse david wolf Java 2 12-10-2012 09:20 AM
How JTable restore original order after sorting? iherage@gmail.com Java 0 09-14-2007 04:33 PM
CSS: "tagname.classname" or ".classname" Ante Perkovic Javascript 2 12-25-2003 03:02 AM
Is `new classname' the same as `new classname()' ? Hongzheng Wang C++ 32 12-05-2003 05:29 PM
classname::classname a type ? Oliver S. C++ 1 09-11-2003 07:47 PM



Advertisments