Why does the following output an empty string for style.backgroundImage? How can I retrieve the height and width of the image so that I can set the dimensions of the div appropriately?
<!DOCTYPE html>
<html>
<head>
<link href="test.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="myDiv" onclick="outputBGImageUrl(this)">
Click To Get BG Image Property
</div>
<script type="text/javascript">
function outputBGImageUrl(elem){
var bgImage = elem.style.backgroundImage;
console.log(bgImage);
}
</script>
</body>
</html>
CSS:
.myDiv{
background-image:url(box.jpg);
}