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 Interactive Web Pages with JavaScript Selecting Elements and Adding Events with JavaScript Perform: Event Handling

John Coolidge
John Coolidge
12,614 Points

I don't understand event handling, any resources?

As I watch these videos again and try to use the concepts to build my own app, I don't understand event handling very well at all. If I can't explain it to myself (as if I am teaching someone) then I know I don't have it down at all. I've tried google in order to find more information about event handling, but I'm always given results that, to me, are far too technical and textbookish. I'm dumb and I need a dummy's version, something that isn't packed full of jargon and other things that lend to my misunderstanding. Does anyone know of any resources out there specifically suited to beginners and isn't loaded with technical jargon that exists only to confuse? Thanks!

4 Answers

I've always found this to be a great reference:

http://eloquentjavascript.net/14_event.html

There is some technical language used, but for the most part it is rather straight forward. I hope this helps ;)

John Coolidge
John Coolidge
12,614 Points

Thanks so much (and also to Vyacheslav for the book recommendation, which is on my wishlist). The online resources are handy, as long as I can find what I'm looking for in the thousands of possible pages of "help". After a quick browse through some of the info, it does appear to be a bit less jargon-heavy than other websites I've seen.

You are welcome :)

Not a problem! any time, and I hope it helps!

I would recommend buying this book.

It's a great book for beginners and advanced learners, also design and the layout of the book makes it perfect for future reference.

erik Merc
erik Merc
137 Points

This is a great book. Reading this while also doing treehouse really helps clear things up.

Jeremy Castanza
Jeremy Castanza
12,081 Points

John, it may be helpful to just put it in context and ask specific questions about the topic. Event Handling is a broad topic. However, to put it into simple terms, it's basically a combination of something that happens at a single point in time that has a cause and effect type of reaction. Events are almost infinite in the world of computer programming.

For example, some events might be the following:

  • A page loading
  • A timer reaches zero
  • A user hits the ESC button
  • A user clicks the X on a window
  • The mouse is moved two inches

The common factor in all of these is that it's something happening at a specific point in time.

Usually, it's important because the event will be used to trigger something.

For example, when a page loads, you may want code to execute a popup window. When a timer reaches zero, you may want something to print. When a user hits the ESC button, you may want to close a dialog box. Lastly, when a user clicke on the X on a window, you may want something to disappear.

Hope this helps!

Hi John,

I have the same questions as you, I'm trying to get my head wrapped around asynchronous programming (AKA 'non-blocking' or 'event-driven').

I am making my way through this tutorial: http://book.mixu.net/node/ch7.html

If you have not already, install Node.js on your platform and get on a first-name basis with it. I've had it installed for less than a week and am already learning a lot. What I'm learning is that there is a little worker inside Javascript (the Event Loop) that is busy responding to events on the message queue. So the way we write code will be partially procedural, and partially declarative. We have to imagine the Event Loop ticking away, and things we ask for vs things we receive being disjoint in time.

The basic basic idea is: Javascript is a language for handling complex I/O, not massive computation. And I/O is millions of time slower than computation. Imagine turning the page of a book, vs asking your assistant to load up a pack mule and travel for a month over a mountain range to visit a library and get a book for you. Similar order of magnitude. So you can get a lot of other work done while you're waiting. When your servant arrives, he rings the doorbell. You say, "Who is it?" He answers, "It's me, Callback!" Now you're ready to work on projects depending on the arrival of that book.

Take care, good luck!

-- Cal

John Coolidge
John Coolidge
12,614 Points

Thanks Calvin! Truthfully, I'm not even sure what Node.js is, though I have heard of it. I'm sure I've seen a Treehouse course on it somewhere. I'll get to it in time though. I try to not expand myself too much in too many directions, otherwise I get frustrated at a lack of progress because I'm all over the place. But I will at least read the link that you posted to get my head around event handling. Thanks again. :)