JavaScript from Null: Chapter 5 – Events

As we move forward with JavaScript University, today, we’ll learn how to add event handlers to elements on the page. Unfortunately, this can be more cumbersome than we’d hope, due to the fact that Internet Explorer must always be the black sheep. Nevertheless, we’ll learn how to abstract these inconsistencies away to our custom utility function.

As with every JavaScript from Null screencast, it’s not essential that you view the previous entries in the series before watching.

Catch Up

In this Screencast, you’ll Learn About:

  • Working with .addEventListener
  • Working with IE’s .attachEvent
  • Differences in the way browsers handle events.
  • Capturing phase vs. event bubbling
  • Building a utility function to abstract our cross-browser event handling.

Chapter 5: Events

Other Viewing Options

Ready to take your skills to the next level, and start profiting from your scripts and components? Check out our sister marketplace, CodeCanyon.

CodeCanyon


Related Posts

Add Comment

Discussion 34 Comments

  1. Elijah Manor says:

    Nice tutorial Jeff ;)

    FYI, in IE8 console.log will work if you have the Developer Tools window open (F12). Strangely enough, it will continue to work (without errors) if you close the Developer Tools window. Sounds like a bug, but it works ;)

    Here is a screenshot… http://j.mp/9ktJVK

  2. Dustan says:

    i think we should change net.tutsplus.com to jeffreyways.tutsplus.com. hot dang boy, you tear this place up!

  3. Kyle says:

    Great tutorial!
    I’m just wondering what happens when you need to pass parameters into the function with the addEventListener since the function that’s being called doesnt get the brackets. If I add the brackets does the function get executed when the document loads?

  4. Andrew says:

    These tutorials are great, they also give me a greater appreciation for jQuery.

  5. Thoer says:

    I loved the way DoSomething turned out to be doSomething automagicly! :)

    Nice tutorial thought, thank you!

  6. khaled says:

    Nice tutorial ! thank you useful information

  7. Wow !

    That’s great !

    Thanks !

  8. Jamie says:

    I missed this series. Please keep it going!

    Thanks

  9. Daniel says:

    Thank you Jeffrey, you’re awesome! I’m really enjoying these JavaScript from Null screencasts. Keep ‘em coming!

    I have the same question as Kyle above. I’ve never got the hang of that…

    For a future tutorial I would love to see how to best do DOM-manipulation

  10. khaled says:

    in the function addEvent can’t we make it like this for the capture
    addEvent(obj, evt, fn, capture=false)
    so we make a default value for it rather than make it a if statment

    • Jonas says:

      Unlike with PHP, you can’t provide default values like that with JavaScript, as far as I know. To provide a default value of an argument, you would do the following:

      function test(name) {
      if (!name) name = ‘Something’
      }

      The PHP version of it would be:

      function test($name = ‘Something’) {
      }

  11. DesignLovr says:

    I just started with the first video (complete javascript noob) and have to say it’s a great way to learn javascript

  12. very nice tute today i came to know about this site
    this rocks man

  13. Tom Van Assche says:

    Great tutorial man!

    Also, please dont forget to finish the “CodeIgniter From Scratch”-series ;)

  14. Adikari says:

    thanks for this series.. I am really enjoying and hope you will continue..

  15. Khalil says:

    Thank you Jeff for keeping this series continue…

    Please teach us about .htaccess with your screencast video series…

    waiting …

  16. misterbingo says:

    Thanks Jeffrey, you taught really good compared to others ;)

  17. Nice Tut, JavaScript can be rather daunting

  18. Zak Groner says:

    Yes! Finally, I’ve been waiting for this for what feels like years!

  19. ryan says:

    I’m really enjoying this JavaScript from Null screencast series. Keep ‘em coming!

  20. gio says:

    good tut , many thanks and looking forward to more!

  21. levon says:

    Jeffrey, when a new lesson?

  22. Nick Toye says:

    What is Capture? You mentioned in the screencast that you were going to mention more about it, but you never really did.

  23. AlexD2B says:

    Hey Jeffrey, thanks for this awesome series. I was wondering if you will show us in this series how to create a js plugin and how to integrate it in a html or php if it’s possible. For example in a php register form how to include a password strength plugin.

    Oh, and one other thing. I was looking over CodeCanyon and in the JavaScript script section I saw that every file was written in a js library, and then I checked the upload form in JavaScript and I saw that you have to select a js library, so my question is, why can’t you upload files with raw js.

    So, if I asked some stupid questions sorry.

  24. Rockstar79 says:

    Great tutorials Jeffrey!

    Looking forward to the next ones as always

  25. This is a fantastic tutorial, when can we expect the next installment?

Add a Comment