I have a css content with xhr load as the following code,
var xhr = new XMLHttpRequest();
xhr.open('GET', 'my.css');
xhr.onreadystatechange = function () {
if (this.readyState == this.DONE) {
xhr.onreadystatechange = null;
var style = $('<style/>').html(this.responseText);
// it will print a dom string in dev console.
console.log(style[0]);
}
};
xhr.send();
So far I only know how to load the css
content via ajax
,
but I want to let the css content become a StyleSheet
object, just like to access the document.styleSheets[n]
,
I can't find any methods to do this, is there a way to do this?
my question is not apply or insert the css rules to the document, my question is how to let the css content string become a StyleSheet object, https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet