I am having a problem with connecting a click event to a dynamically added dom element. I add a new dom element like this:
var link = dojo.create("a",{
className: "deleteDnd",
innerHTML: "Delete"
},this.domNode,"first");
I would now like to add a click event to this dynamically added link, however I have tried to add the event numerous times but it fails. I am able to connect the event using firebug after the element has been appended. Is there a way to connect the event whilst creating the element something like :
var link = dojo.create("a",{
className: "deleteDnd",
innerHTML: "Delete"
},this.domNode,"first");
dojo.event.connect(link, "onclick", function(node, index, nodelist){
console.log("was clicked");
});
Any help would be greatly appreciated.
The function
dojo.event.connectdoesn’t exist anymore in the newer versions of Dojo. Try using justdojo.connectinstead.You’ll also notice that the link’s event handler function will only get one argument (the event), not node, index and nodeList.