Reputation:
I try use Dojo framework, but i can't use handlers(events) on href or some else element. Thanks.
HTML:
<a class="one" href="#">text_one</a>
<a id="two" href="#">text_two</a>
JS:
require(
["dojo/query", "dojo/_base/connect", "dojo/on", "weather/handlers", "dojo/domReady!"],
function(query, connect, on){
var test = new weather.handlers;
test.getCities();
query(".one").forEach(function(node, index, nodelist){
on(node, "onClick", function(evt){
console.log("one clicked!");
})
});
query('#two').on('onClick',function(){
console.log('two clicked!');
})
}
);
Upvotes: 0
Views: 1374
Reputation: 318
The dom event onClick
was used before Dojo 1.7 where dojo.connect
was used to register event listeners.
For example:
dojo.connect(node, "onclick", callback)
But from Dojo 1.7 onwards
,a new lightweight dojo/on module is introduced which uses the syntax as:
on(nodel, "click", callback)
The on
prefix was dropped, and onclick
became click
Upvotes: 0
Reputation: 10559
The name of the DOM event you want to listen to is click
, not onClick
. Listening to onClick
on a DOM element using dojo/on
will do nothing.
If you're going to be hooking up an event handler for multiple homogenous elements, you might also want to read about Event Delegation in the Events with Dojo tutorial.
Upvotes: 1