Skip to content

Instantly share code, notes, and snippets.

@koba04
Created May 2, 2014 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koba04/59d5fe30365133704e56 to your computer and use it in GitHub Desktop.
Save koba04/59d5fe30365133704e56 to your computer and use it in GitHub Desktop.
Compute backgroundImage url from css class.
computedBackgroundImage: function(className) {
var div = document.createElement("div");
div.style.display = "none";
div.className = className;
document.body.appendChild(div);
var url;
var style = window.getComputedStyle(div)["background-image"];
if (style) {
var match = style.match(/^url\((.*)\)/);
if (match) url = match[1];
}
document.body.removeChild(div);
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment