Get the background image property of div through js
- 2020-03-26 21:24:16
- OfStack
I didn't notice the background-image property of div before, but just set its url. I encountered a problem today and hereby make a record.
In js you want to get the image attribute
Notice that in bold, the div is background-image, and the backgroundImage is used to get the property. I think all of these styles with a "-" are going to do this, and this is going to be tested,
Record the problem first.
<div id="img_2" style="width:133px;height:95px; cursor:pointer; background-image: url('Chrysanthemum.jpg');" onclick="tempClick()"></div>
In js you want to get the image attribute
document.getElementById('img_2').style.backgroundImage;
Notice that in bold, the div is background-image, and the backgroundImage is used to get the property. I think all of these styles with a "-" are going to do this, and this is going to be tested,
Record the problem first.