What's a more idiomatic way to write this:
Element.addMethods({
toggleClassName: function(element, className){
var element = $(element);
(element.hasClassName(className)) ?
element.removeClassName(className) : element.addClassName(className);
return element;
}
});
This works, but it's got that really long line in the middle. How do you do
what PHP calls a "variable variable" in JavaScript to execute the correct
method (add/remove) based on the input without writing it all out long-hand?
Walter
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.