Im making a custom theme for my app and i want to change the color of scroll bar from "#1a1a1a" to "FF5555" when i click a button in javascript only. i’ve tried multiple things such as document.body.style.scrollbarBaseColor = "#FF5555";
but it doesnt work.
Im not using any framework its just plain html,css and js
2
Answers
I don’t know why are you trying to do it with javascript.
But here, I just made an scratch on..
First, I create an element
style
so we can add css here.Second, we need to add style for our scrollbar on the created element(
style
). So, usingcreateTextNode
we add our style on STRING data type.Last, we need to activate the created style on our html file. By doing
getElementByTagName
we’ll get HTMLCollection from [head] tag then we add array[0] so we can access its properties tho append the createdstyle
.The probably cleanest solution is to do the styling in CSS and "guard" it with a class that you add/remove on demand.
That way you have proper separation between JavaScript and CSS.