Select an element that doesn't have a background set
Question
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.
Solution
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');
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow