I'm trying to understand how the jquery pertaining to modifying stylesheets works by understanding how to do it with vanilla javascript, but there isn't a lot of resources on the subject that I can find. I already checked the stack over flow page on the subject but I cant figure out what I'm doing wrong.
I have a simple html page and a simple style sheet, with the javascript in the html page in a script tag
html page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="parent"></div>
<script>
let parent=document.getElementsByClassName('parent')[0];
for(let i=0; i<10;i++){
let child=document.createElement('div');
let id= "i"+ i.toString();
child.setAttribute("id",id);
parent.appendChild(child);
}
</script>
</body>
</html>
style sheet
body{
background-color: lightblue;
}
.parent{
display:flex;
flex-wrap: wrap;
flex-direction: column;
}
.parent div{
margin: 5px;
width: 50px;
height: 50px;
background-color: white;
}
console commands
when I style to pull up the stylesheet object, in the console I get the object aka the stylesheet but the cssRules property is set to null, with none of the rules in the style sheet in it. I cant figure out as to why this is.
for example
document.styleSheets //returns StyleSheetList {0: CSSStyleSheet, length: 1}
document.styleSheets[0] /*returns CSSStyleSheet {ownerRule: null, cssRules:
null, rules: null, type: "text/css", href:
"file:///C:/Users/brand/Documents/test/main.css"…}*/