I want to get a css image rule like (URL, Size) in JavaScript like Variable.
Example Show:
- HTML right syntax:
<div id="mydiv"></div>
- The correct CSS syntax:
<style>
body{
background: url('a.png');
background-image-size: cover;
}
</style>
JS error syntax:
<script>
function GetImgVar(){
var imgsrc = document.body.style.backgroundImage;
document.getElementById('mydiv').style.backgroundImage=imgsrc;
}
</script>
source
share