6
If I have the following tag style
:
<style>
body{
color:red;
}
</style>
It would be possible to add another new css rule like inside this style
through the Javascript
?
For example, I want to add this to the end of the first style
I gave as an example:
.class-x {
color:yellow;
}
You can do it using a jQuery append, right? Half a Trash, but it works
– Caio Felipe Pereira
Theoretically, you can use
document.styleSheets
but there’s probably a more practical way (with CSS hierarchy, maybe) of doing what you want. Can you explain better what the goal is? Or is it just curiosity?– Gabe
What is the goal? Have some example that needs this logic?
– RBoschini
@Gabe curiosity. Some do not see utility, but it is not a question of being useful. I just want to learn even if it has a form. After that comment someone must want to give me negatives :)
– Wallace Maxters
Thanks @Gabe! I found this in the reference you sent https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule
– Wallace Maxters
@Wallacemaxters I’ve never used, so I can’t say exactly what is possible to do or not. But I believe that
dcument.styleSheets
be really the way...– Gabe
That would be: var myElements = Document.querySelectorAll(".bar"); for (var i = 0; i < myElements.length; i++) { myElements[i].style.opacity = 0; }
– durtto
That’s not what @durtto
– Wallace Maxters