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 Introduction to jQuery Events Using the on() Method

Jose Gutiérrez
Jose Gutiérrez
9,370 Points

What is the difference between use myButton.addEventListener('click',()=>{}); and use $('#myButton').on('click',...

I am confused, can i use myButton.addEventListener('click' , (event)=>{ do something}); and use $('#myButton').on('click' , fucntion(event){doSomething}); intercahgeably? I know than one is javascript ant the other is jquery but, its possible to use both ways in the same .js file?

2 Answers

Steven Parker
Steven Parker
229,644 Points

:point_right: jQuery adds to JavaScript, but does not remove any JavaScript functionality.

You can think of jQuery as "JavaScript PLUS", since you're still using JavaScript, just with extra features. So yes, any plain JavaScript still works and can be combined with your jQuery. In the background, jQuery is just performing the same JavaScript steps you would use anyway, but providing a more compact interface to you.

Just keep in mind the distinction between jQuery objects and plain DOM elements (as you did above), but otherwise you can mix and match as you wish in your program.

Jose Gutiérrez
Jose Gutiérrez
9,370 Points

Perfectly explained!!! Thanks a lot!