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
You're setting the background property, background and backgroundImage are two seperate properties which is why backgroundImage is empty after setting background. If you want to access just the url part of the background property, you can use the following code:
var wfBg = document.getElementById("widgetField").style.background;
var wfBgUrl = wfBg.match(/(url\(['"]?([^)])['"]?\))/i);
if (wfBgUrl)
{
// Add your code here. wfBgUrl[1] is full string including "url()",
// wfBgUrl[2] would be just the url inside the parenthesis
}
For styles set by css documents:
if (window.getComputedStyle) // For standards compliant browsers
var wfBg = window.getComputedStyle(
document.getElementById("widgetField")
).getPropertyValue("background");
else // for IE
var wfBg = document.getElementById("widgetField").currentStyle.background;