Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 2

Yijiao Wang
Yijiao Wang
1,793 Points

Can someone explain to me how the .on() works in this case?

$("input[type=range]").on("input", changeColor);

In the teacher's notes, instead of using .change(), we use .on("input", changeColor) for Chrome browser because .change() doesn't work for Chrome anymore. My question is, how to understand .on() method and its handler? What does "input" mean in (). I looked up in JQuery API but do not understand it very well. Thanks!

1 Answer

Hi Yijiao,

On is much more versatile than "change" because it looks for something you give it. "input" here is what you give it. for instance you could give it:

$("input[type=range]").on("click", changeColor);

And the changeColor will happen on a click.

But when you would give it:

$("input[type=range]").on("mouseenter", changeColor);

Would make it happen on the mouseenter instead of click.

So you can use on("change".... as well.