remove inline css style "filter"

676 views
Skip to first unread message

cbolson

unread,
Feb 16, 2010, 6:30:16 PM2/16/10
to MooTools Users
Is there a way to remove a style added (by mootools) inline to an
element?

Specifically I want to remove the "filter: ;" from the element once it
has been faded in so as to get around the cleartype problem with IE.

We have setStyle() now I just need removeStyle() ;)

Chris

chone

unread,
Feb 16, 2010, 6:42:19 PM2/16/10
to mootool...@googlegroups.com
hi, you can set the value as ""

ex: element.setStyle('filter', '');

cbolson

unread,
Feb 16, 2010, 6:53:37 PM2/16/10
to MooTools Users
> hi, you can set the value as ""
>
> ex: element.setStyle('filter', '');

Thanks, but that doesn't actually remove it. The style is still there
just with no value (" filter: ;").
To resolve the IE issue it needs to be completly removed (at least iit
does as far as I have been able to test things)

Chris

Ryan Florence

unread,
Feb 16, 2010, 6:58:32 PM2/16/10
to mootool...@googlegroups.com
setStyle('filter','') ?

Sent from my iPhone

cbolson

unread,
Feb 16, 2010, 7:51:44 PM2/16/10
to MooTools Users
hmmm,
This method seems to work on other styles (border, display etc).
However it doesn't seem to work on IE7 for the "filter" style.
Even if define the filter manually like this:
$(element).setStyle('filter','alpha(opacity=40)');

When I try to remove it using setStyle('filter',''); it still leaves
the "filter: ;" in there :(

Here is a mooshell demo:
http://mootools.net/shell/hSd5C/
This does nothing in Firefox as I am only concentrating on the IE
"filter" style.
If you check the html in the IE developers tools, you will see that
the filter style does not get removed :(

Chris

Matthew Hazlett

unread,
Feb 16, 2010, 9:26:39 PM2/16/10
to mootool...@googlegroups.com
Can try something like this to get rid of the declaration

<div id="test" style="background-color:#333333;color:#456789">This is my
tag</div>

Element.implement(
{
removeStyle: function(ele)
{
regex = new RegExp(ele+ '.*?;');
style = this.get('style')+';';
this.set('style', style.replace(regex, ''));
}
});

$('test').removeStyle("background-color");


http://mootools.net/shell/BYNeE/

My regex skills are lacking but this should do the trick.
Maybe someone can fix my regex pattern to make it match better.

Chris

__________ Information from ESET Smart Security, version of virus signature
database 4872 (20100216) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature
database 4872 (20100216) __________

The message was checked by ESET Smart Security.

http://www.eset.com

Matthew Hazlett

unread,
Feb 16, 2010, 11:44:03 PM2/16/10
to mootool...@googlegroups.com
Still a tad messy, but will remove your filter tag no matter where it is in
the inline css.
The JS regex patterns don't include \A or \Z for the beginning and end of
line and [;$] is illegal.

http://mootools.net/shell/QPyND/


-----Original Message-----
From: mootool...@googlegroups.com
[mailto:mootool...@googlegroups.com] On Behalf Of cbolson
Sent: Tuesday, February 16, 2010 7:52 PM
To: MooTools Users
Subject: [Moo] Re: remove inline css style "filter"

Chris

Sanford Whiteman

unread,
Feb 17, 2010, 12:04:13 AM2/17/10
to Matthew Hazlett
> Still a tad messy, but will remove your filter tag no matter where it is in
> the inline css.

Surely you do not see this function removing style.color in IE, n'eh?
You have to do a case-insensitive search.

-- Sandy

Matthew Hazlett

unread,
Feb 17, 2010, 12:35:33 AM2/17/10
to mootool...@googlegroups.com
Oops, add an, "i" to the regex

http://mootools.net/shell/QPyND/1/

or just change

regex = new RegExp('[~;\\s]' + ele + '.*?[;~]', "i");

-- Sandy

cbolson

unread,
Feb 17, 2010, 4:25:59 AM2/17/10
to MooTools Users
Thanks Matthew, that is pretty much exactly what I was looking for.

Chris

Reply all
Reply to author
Forward
0 new messages