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

后端 未结 5 913
陌清茗
陌清茗 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:17

    Get the background property:

    alert(document.getElementById("widgetField").style.background);
    

    Displays : url(includes/images/datepicker_open.png)

    Edit: Andy E's answer should be close to what you need. One difference is that for IE you need

    currentStyle.backgroundImage 
    

    instead of

    currentStyle.background
    

提交回复
热议问题