A jQuery plugin is applying an inline style (display:block
). I'm feeling lazy and want to override it with display:none
.
What's the best (lazy) way?
A jQuery plugin is applying an inline style (display:block
). I'm feeling lazy and want to override it with display:none
.
What's the best (lazy) way?
$el.css({ height : '', 'margin-top' : '' });
etc...
Just leave the 2nd param blank!
Change the plugin to no longer apply the style. That would be much better than removing the style there-after.
you can create a jquery plugin like this :
usage
Update: while the following solution works, there's a much easier method. See below.
Here's what I came up with, and I hope this comes in handy - to you or anybody else:
This will remove that inline style.
I'm not sure this is what you wanted. You wanted to override it, which, as pointed out already, is easily done by
$('#element').css('display', 'inline')
.What I was looking for was a solution to REMOVE the inline style completely. I need this for a plugin I'm writing where I have to temporarily set some inline CSS values, but want to later remove them; I want the stylesheet to take back control. I could do it by storing all of its original values and then putting them back inline, but this solution feels much cleaner to me.
Here it is in plugin format:
If you include this plugin in the page before your script, you can then just call
and that should do the trick.
Update: I now realized that all this is futile. You can simply set it to blank:
and it'll automatically be removed for you.
Here's a quote from the docs:
I don't think jQuery is doing any magic here; it seems the
style
object does this natively..removeAttr("style")
to just get rid of the whole style tag....attr("style")
to test the value and see if an inline style exists....attr("style",newValue)
to set it to something else