How to change the color of Slider single label?

Hi!
Is it possible to change a single label color of slider (e.g. 1 in blue, 6 in red) directly in JS (online script)?

Best regards,
Thomas

In PsychoPy you can do that like this:

mySlider.labels[0].color = 'red'  # label on the left
mySlider.labels[-1].color = 'blue'  # label on the right

and the PsychoJS lib does a pretty good job of mimicking the Python equivalent, so I think that would be worth a try (actually, I don’t know if negative indexing works in JS so you might need to count up instead)

Hi,
unfortunately it doesn’t work in any variation I tried - I get message: TypeError: Cannot create property ‘color’ on string or experiment simply doesn’t start.

Hi @tomm, just needs a slight amendment. Try:

mySlider.labelObjs[0].color = 'red'  # etc
3 Likes

The following line is working perfectly in python, however I am not sure what should be its equivalent in javascript.

mySlider.labelObjs[0].color = 'red'

I am using the type “slider” for the slider component but when assigning the color of the the bar it also changes the color of the labels. I would like the bar in the LightGrey and the labels in Black but I haven’t been able to do that so far in javascript.