Use jQuery to find out if a <div> has a background image?

Is it possible to use jQuery to check if a #pagebackground image has - it #pagemight look like this:

<div id="page" style="background-image: url(xxx)"></div>

If it contains a background image, it should add a class to #page

+5
source share
2 answers

The default value for background-imageis "none". Therefore, you can do it as follows:

if ($('#page').css('background-image') != 'none') {
  alert('There is a background image');
}
+17
source
var image = $('#page').css('background-image');

The task must be completed.

+1
source

All Articles