tags:

views:

868

answers:

6

a jquery plugin is applying an inline style (display:block), I'm feeling lazy and i want to override it with display:none,

what's the best (lazy) way?

+4  A: 

.removeAttr("style") to just get rid of the whole style tag... .attr("style") to test the value... .attr("style",newValue) to set it to something else

kekekela
This will affect _all_ inline styles, not just `display`.
SLaks
sounds good ill give it a try and let you know, i never use inline styles normally so happy to clear all inline styles
Haroldo
+1  A: 
$("[style*=block]").hide();
David Morton
+1  A: 
$('div[style*=block]').removeAttr('style');
antpaw
+3  A: 

You can set the style using jQuery's css method:

$('something:visible').css('display', 'none');
SLaks
+1 for `:visible`. Now, go all the way and use `.hide()`.
Kobi
@Kobi: He's asking about any inline style.
SLaks
err, what? I probably don't understand something. I'm thinking about `<div style="display:block;">`, `$('div').hide()` .
Kobi
@Kobi: `hide` addresses one special case of modifying inline styles. This answer addresses all cases. (`hide/show` also have a limitation as two which two values are toggled. i.e. none->block or none->inline.)
Joel Potter
@Joel: `hide` / `show` will remember the old value of `display` and restore it correctly.
SLaks
@SLaks: Cool. That must have been added recently, as I remember having trouble with it before.
Joel Potter
@Joel: http://api.jquery.com/hide/: The matched elements will be hidden immediately, with no animation. This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline.
SLaks
+1  A: 

The Lazy way (which will cause future designers to curse your name and murder you in your sleep):

#myelement 
{
    display: none !important;
}

Disclaimer: I do not advocate this approach, but it certainly is the lazy way.

Joel Potter
A: 

Change the plugin to no longer apply the style. That would be much better than removing the style there-after.

Josh Stodola
hence the 'lazy'!cant be arsed to find which bit of which plugin it is!
Haroldo
I don't know how you define lazy, I just answered how I would do it. Seems to make sense to fix the problem where it originates as opposed to patching things up outside of the plugin. I foresee messinesss when doing it that way.
Josh Stodola