Created
May 2, 2014 10:15
-
-
Save koba04/59d5fe30365133704e56 to your computer and use it in GitHub Desktop.
Compute backgroundImage url from css class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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