-
-
Save AleksueiR/1368f925f63fab665a0d to your computer and use it in GitHub Desktop.
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
(function () { | |
var elCache = []; | |
var styleCache = []; | |
forceStyle = function (el, obj) { | |
if (elCache.indexOf(el) == -1) { | |
elCache.push(el); | |
styleCache.push(el.style.cssText); | |
} | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
el.style.cssText += ';' + prop + ':' + obj[prop] + ' !important'; | |
} | |
}; | |
}; | |
restoreStyle = function (el) { | |
var index = elCache.indexOf(el); | |
if (index == -1) { | |
return; | |
} | |
el.style.cssText = styleCache[index]; | |
elCache.splice(index, 1); | |
styleCache.splice(index, 1); | |
}; | |
})(); | |
// Example usage: | |
forceStyle(document.body, {margin: '10px', 'border-left': '2px solid red'}); | |
restoreStyle(document.body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you ever get this working considering the usage string is totally a joke and isn't even consistent in the usage of quoting or the tokens? I struggled to even get it working it sure looks like a quickly thrown together wireframe of a function that was never tested but I really liked the idea so was hoping someone had gotten it working.