Skip to content
Advertisement

Javascript change webkit style with variables

Summary

I’m working on an input[type=range] that essentially looks like Chrome’s default but the thumb is green until clicked. That’s the end goal. Through a couple answers that are now buried deep in my browser history (hence lack of credit to them) I am able to get it MOSTLY working how I want.

Issue

The onLoad code works how I want it to except for one major issue: It affects all elements, not the individuals. I simply can’t figure out how to get this line:

JavaScript

to be set in the same manner as this line:

JavaScript

Supporting Code

Here are those two lines in my ‘working’ code:

JavaScript
JavaScript
JavaScript

Yes, I know it’s a value that’s less that min. I’m leveraging this for essentially making changing it a requirement (think like instead of 5 radio buttons for a survey). That’s also the reason I want to start with a green thumb: Green means it’s not been touched yet. This is my focus.

Thank you in advance.

Advertisement

Answer

I think you can’t write the ::-webkit-slider-thumb, just like other pseudo-classes, as inline-style. See this thread.

But you can complete your “hack” with the <style> element. Create one for each input and add a unique selector (e.g. id or [name="rangeInput1").

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement