| Reference | Downloads | Github

Changing line colour with mouseover [Javascript]


I want the border of a rect. stimulus to change colour upon mouseover. I have used the following Python code which works well in the builder:

if Male.contains(mouse):
    Male.lineColor = 'red'
    Male.lineColor = 'black'

And the following for Javascript:

if (Male.contains(mouse)) {
    Male.lineColor = "red";
} else {
    Male.lineColor = "black";

However, this code does not work online, so my assumption is that there is some problem with the JS syntax. I’m sure there’s probably a very small mistake somewhere, but I’m not quite sure what it is. Thanks in advance.


Are you using the auto translate.

Your Javascript is missing a bracket } at the end but maybe that’s just your copy and paste.

Do you get an error?

Best wishes,



Thanks for the reply. Yes, I used the auto-translate to help.

The Javascript bracket was a mistake in my copy and paste, I’ve amedned the original message to include the bracket.

I don’t get any errors with this code, but the line color of the rect stimulus remains black.

Ah – I’ve spotted the issue. I had a problem with colours which I’ve solved by defining them at the start of the experiment.

e.g. Begin Experiment
Python - red=[1,-1,-1]
Javascript - red = new util.Color([1, -1, -1]);

Then use red without quotes in your code.

This is in my crib sheet.

Best wishes,


That has worked perfectly, thank you so much! I’ve also looked at the crib sheet and it looks like a lifesaver, so thank you for that too :slight_smile: