Removing a style?

32 views
Skip to first unread message

andy....@gmail.com

unread,
Aug 3, 2008, 7:57:02 PM8/3/08
to Prototype & script.aculo.us
Is there a way to remove a custom-style set on an element such that
the element will return to its stylesheet style? For example, on drag-
and-drop, styles are set on the dragged element and it would be great
if I could call something like
element.removeStyle(['opacity','top,...]) to restore the element to
it's stylesheet style (opacity is easy to reset but there are other
things like top, left, position for which I'd rather not hard-code
values).

thx
a

kangax

unread,
Aug 3, 2008, 8:26:56 PM8/3/08
to Prototype & script.aculo.us
On Aug 3, 7:57 pm, "andy.kri...@gmail.com" <andy.kri...@gmail.com>
wrote:
This is usually done by assigning an empty string to a property, e.g.:

element.style.backgroundColor = '';

As far as `removeStyle` helper, something like this should work:

Element.addMethods({
removeStyle: function(element) {
element = $(element);
$A(arguments).slice(1).each(function(style) {
element.setStyle({ style: '' })
});
return element;
}
});

// then

$(someElement).removeStyle('color', 'opacity', 'position');

--
kangax

Alex Hernandez

unread,
Aug 4, 2008, 4:37:51 PM8/4/08
to Prototype & script.aculo.us
I suggest that you use the addClassName() and removeClassName()
methods like in:

$('elementID').addClassName('draggable');

and

$('elementID').removeClassName('draggable');

HTH

Alex


On Aug 3, 7:57 pm, "andy.kri...@gmail.com" <andy.kri...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages