I have a div called "dynamic" with some text in it and I am adding style to it using javascript
var styleElement = document.createElement("style");
styleElement.appendChild(document.createTextNode("#dynamic { color: red; }"));
document.getElementsByTagName("head")[0].appendChild(styleElement);
It works great. Same thing, I'm trying to add some CSS for the scrollbar, and we can achieve this with the css code below:
div ::-webkit-scrollbar {
-webkit-appearance: none;
width: 7px;
}
div ::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: rgba(0,0,0,.5);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}
So now I added it using javascript as follows:
var styleElement = document.createElement("style");
styleElement.appendChild(document.createTextNode("
div ::-webkit-scrollbar{
-webkit-appearance: none;
width: 7px;
}
div ::-webkit-scrollbar-thumb{
border-radius: 4px;
background-color: rgba(0,0,0,.5);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}
"));
document.getElementsByTagName("head")[0].appendChild(styleElement);
But this does not work as expected.
My question is:
For the first scenario, it worked fine (adding color to the "dynamic" div using javascript). But for the second scenario, if I add CSS for the scrollbar using javascript, it does not work. If the first script works, then the second script should work.
, css webkit-scrollbar javascript?
jsFiddle