views:

22

answers:

1

The title pretty much says it all.

Using jQuery, I need to select all elements that do not have a background color or image defined, and apply at least a white background to it.

Thanks!

+1  A: 

If you know which specific elements you're looking for you could do something like this:

var els = $('div');

els.each(function(idx, el){
    if ($(el).css('background-color') == '' || $(el).css('background-image') == '')
    {
        $(el).addClass('white-background');
    }
});
Darrell Brogdon
ok, so this worked great! The only thing now, is that it doesn't detect styles applied via a css file...only inline styles. Any ideas with that?
tscully
ok, nevermind, it is reading the css, but the values are not defaulting to ''. They are defaulting background-color to 'transparent' and background-image to 'none'. So I just adjusted the function above accordingly.Thanks for your help!
tscully