How can I determine the background image URL of a div via JavaScript?

后端 未结 5 920
陌清茗
陌清茗 2020-12-17 22:58

I\'ve found plenty of information on how to change the background image of a div using JavaScript, but I am trying to use JavaScript to determine which background image is b

5条回答
  •  余生分开走
    2020-12-17 23:29

    Try this:

    var img = document.getElementById('widgetField'),
    style = img.currentStyle || window.getComputedStyle(img, false),
    bi = style.backgroundImage.slice(4, -1);
    

提交回复
热议问题