JavaScript from Null: Chapter 5
basixvideos

JavaScript from Null: Chapter 5 – Events

Share

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


Jeffrey Way is JeffreyWay on Codecanyon

Related Posts

Add Comment

Discussion 56 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?

  26. todd valentine says:

    Watched each episode of this series multiple times now. Can’t wait for the next one.

  27. Arthur Maroulier says:

    As always, easy to understand, explained very well. It’s awesome.
    I’m following this serie with interest.

    At the top there is a link to get it in iTunes as a podcast, but I can’t find it in the store.

  28. What happened to this series? The last one was in January.

  29. Congratulation for the amazing series!! Your tutorials are always easy to understand and with a complete explanation!!!

    I was wondering… When the next amazing episode?

  30. chris says:

    When is chapter 6 coming?!

    So good, thanks Jeff!

  31. Amit says:

    What is the point of capture? Does it speed up the script? How does one use it and when?

  32. Bryan says:

    Great series jeffrey, learned a lot already !

    Are there any more or was this the last one of the series ?

  33. asdasd says:

    Delayed as hell… give us all the chapters pl0x

  34. Sergio Varela says:

    Nice tutorial Jeff (Y)

  35. Sudanking says:

    That is really great…..
    Any one now where I can find next episode??

  36. Norguad says:

    Hallo Jeff,

    thanks a lot for this stuff!!!

    are you going to continue with this series?

  37. Hi Jeffrey. Your Screencast rocks so much! Please continue this series I’m going crazy it’s so good !

  38. John says:

    Great series, I hope you follow this up with more!

  39. Tim says:

    Hey Jeffrey awesome tutorials, learning this way for my exams Webscript you really help me out with the good explanation.

    I should mention that you should give Aptana Studio a try help alot in js .
    works also on mac :p

    hope to see you soon with a new episode :)

  40. Albertgrala says:

    Thanks for the tutorials!!! I learn a lot!! I hope you will continue this series. But 7 months without another chapter may say javascript tutorials finished :(

  41. Dorin says:

    Please go on with the great tutorials!

  42. Ricardo says:

    Please go back to the series. They are just the best on Internet.

  43. Phil1 says:

    Thanks Jaffrey for a great series, Hope it wiil be back soon!

  44. Mark says:

    Hi Jeff,

    great tut as usual, echoing some of the other comments here regards ‘bubbling’, I understand from your explanations what it is but I’m struggling to see why you would or wouldn’t use it, it would be great in the next episode to have a practical example of when it would be good to use it (or not as the case maybe)

    Thanks!

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.