This topic has been closed. No new entries allowed.
Reason: You can now post comments on articles on Dev Opera
You need to be logged in to post in the forums. If you do not have an account, please sign up first.
49 - Handling events with JavaScript
You can't do anything with JavaScript in response to user actions without using events. In fact, they have featured in some of the previous articles without really being explained. In this article, Robert Nyman chronicles at the evolution of JavaScript/HTML events, before looking at how events are made to work across different browsers in modern JavaScripting. Concepts such as bubbling and event object references are covered.( Read the article )
Originally posted by stelt:
typo: shouldnote
HTML of "Stopping event bubbling" is wrong:.....
Typos fixed - thanks!
I've also improved the code indenting.
Chris Mills
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com
22. January 2011, 00:31:04 (edited)
Under "Applying events to certain elements", the example:
uses "evt" without having declared it. I don't know if this is an implicitly-passed variable for event handlers (it's not mentioned), but other examples in the article explicitly define it as an parameter to the event handler.
In "Stopping event bubbling", the HTML is wrong:
Values for the "id" attribute are supposed to be unique for a document. They're not here — each <a> has the same id. I'm not sure what the code that uses this HTML does.
addEvent(window, "load", function () {
var links = document.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
addEvent(links[i], "click", function () {
alert("NOPE! I won't take you there!");
// This line's support added through the addEvent function. See below.
evt.preventDefault();
});
}
});
uses "evt" without having declared it. I don't know if this is an implicitly-passed variable for event handlers (it's not mentioned), but other examples in the article explicitly define it as an parameter to the event handler.
In "Stopping event bubbling", the HTML is wrong:
<div>
<ul>
<li>
<a href="http://www.opera.com/" id="stop-default">Opera</a>
</li>
<li>
<a href="http://www.opera.com/products/dragonfly/" id="stop-default">Opera Dragonfly</a>
</li>
</ul>
</div>
Values for the "id" attribute are supposed to be unique for a document. They're not here — each <a> has the same id. I'm not sure what the code that uses this HTML does.