There are three divs in the code snippet below.
<div id="div#product_img_wrapper">
<div id="product_design1" class="timage" style="z-index: 20; background-image: url('');"></div>
<div id="product_design2" class="timage" style="z-index: 20; background-image: url('');"></div>
<div id="product_design3" class="timage" style="z-index: 20; background-image: url('');"></div>
</div>
The following jQuery function is used to iterate through the divs above.
jQuery('div#product_img_wrapper div').each(function(){
var background = jQuery(this).css('background-image').replace('url(','').replace(')','');
if(background != 'none')
{
console.log(jQuery(this));
console.log(background);
}
});
Output
"http://localhost/project/index.php?option=com_project&controller=project&task=project&method=1"
"http://localhost/project/index.php?option=com_project&controller=project&task=project&method=1"
"http://localhost/project/index.php?option=com_project&controller=project&task=project&method=1"
The goal is to retrieve the background-image attribute of each div. However, the code returns the browser URL instead. What could be the issue with the above code? Why does jQuery(this).css('background-image') retrieve the browser URL?