I am new to Dojo and trying to understand how to handle events. There seems to be at least 3 or 4 different ways to bind events to elements. To add to the confusion, some methods seem to have been deprecated with the new v1.7, so even limiting my Web search to recent months didn't help.
Just having this example work would be a good start (one thing I haven't yet figured out is which modules should be loaded for what):
But beyond this I am hoping to find a good reference.
Here's a simplified working example.
// alert url when hover over link
require(["dojo/query", "dojo/on", "dojo/domReady!"], function(query, on) {
query("a").on("mouseover", function(evt) {
alert(evt.target.href);
});
});
http://jsfiddle.net/RichAyotte/sVJWY/6/
Here's an example with a forEach.
require([
"dojo/query"
, "dojo/on"
, "dojo/domReady!"], function(query, on) {
query("a").forEach(function(node) {
on(node, "mouseover", function(event) {
alert(node.href);
});
});
});
http://jsfiddle.net/RichAyotte/sVJWY/7/
Note the onmouseover -> mouseover in the code or you could use the mouse extension.
require(["dojo/on", "dojo/mouse"], function(on, mouse){
on(node, mouse.enter, hoverHandler);
});
http://livedocs.dojotoolkit.org/dojo/on
For your example this is the correct javascript on dojo style
require(["dojo/dom", "dojo/parser", "dojo/domReady!","dojo/on","dojo/query"],
function(dom,parser,domReady,on,query){
dojo.ready(function(){
query("a").forEach(function(node){
on(node,"mouseover", function(event){alert(node.href);});
});
});
});
you were laking the dojo query module, and the dojo style for the new AMD system