Skip to content

Instantly share code, notes, and snippets.

@Arkmind
Created June 27, 2018 20:43
Show Gist options
  • Save Arkmind/34ff9333f1ea11b78acb4674f4e489aa to your computer and use it in GitHub Desktop.
Save Arkmind/34ff9333f1ea11b78acb4674f4e489aa to your computer and use it in GitHub Desktop.
const UID = {
_current: 0,
getNew: function(){
this._current++;
return this._current;
}
};
HTMLElement.prototype.pseudoStyle = function(element, prop, value){
var _this = this;
var _sheetId = "pseudoStyles";
var _head = document.head || document.getElementsByTagName('head')[0];
var _sheet = document.getElementById(_sheetId) || document.createElement('style');
_sheet.id = _sheetId;
var className = "pseudoStyle" + UID.getNew();
_this.className += " "+className;
_sheet.innerHTML += " ."+className+":"+element+"{"+prop+":"+value+"}";
_head.appendChild(_sheet);
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment