How can I grab entire css from <style id="myId" type="text/css"> to push it into a JSON file?
I am adding dynamically css to <style>, so in my html the style is empty.
Tried with $('#myId').text(), $('#myId').html() with no luck.
I need for this type of output:
function addRule(selector, rules) {
var stylesheet = document.getElementById('myId');
if (stylesheet) {
stylesheet = stylesheet.sheet;
if (stylesheet.addRule) {
for (var i = 0; i < selector.length; ++i) {
stylesheet.addRule(selector[i], rules);
}
} else if (stylesheet.insertRule) {
stylesheet.insertRule(selector.join(',') + ' { ' + rules + ' }', stylesheet.cssRules.length);
}
}
}
function pushToJson(){
item {}
dataCSS = []
item ["myCSS"] = '?????';
// here I need the css
// eg: "h1 {margin:0;} .title {padding:10px 0;}"
dataCSS.push(item);
}
addRule(['.title, h2'], 'color:red;');
Any help?
.text()seems to work just fine for me.document.getElementById('myId').innerHTML.html(), or I am wrong?<style>?stylesheet.cssRules: developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet