elem.style refers to the inline styles set in the element.
the correct way to get the background image can be found here: Javascript: Get the original <div> URL
It doesn't matter here (with improved url retrieval ;-)).
var img = document.getElementById('your_div_id'),
style = img.currentStyle || window.getComputedStyle(img, false),
bg_image_url = style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2').split(',')[0];
And here is how you get the sizes:
var image = new Image();
image.onload = function(){
var width = image.width,
height = image.height;
}
image.src = bg_image_url;
source
share