I'm been digging a little in Style Sheets, I was trying to access a <style>
tag the same way I could access a styleSheet element, for example.
<style id="myStyle">
</style>
var myStyle = document.getElementById("myStyle");
alert(myStyle.cssRules[0]);
But this didn't work, then I decided to check the type of the <style>
tag.
alert(myStyle);
And it gave me this :
[object HTMLStyleElement]
So I checked the type of a styleSheet.
alert(document.styleSheets[0]);
And it gave me this:
[object CSSStyleElement]
So what is the real difference? And how can I access the rules in <style>
tag other than using .innerHTML
? And how can I create a new styleSheet
?