Dojo.Connect Event not triggered - why?

I am trying to connect the onMouseDown event to an image using dojo.connect , for example:

 dojo.connect(dojo.byId("workpic"), "onMouseDown", workpicDown); function workpicDown() { alert("mousedown"); } 

Similar code a few lines later, when I connect onMouse* events to dojo.body , it works completely correctly.

but when I click on the image, I do not see a warning window, so the event is not raised. Why is this?

+4
source share
2 answers

"onMouseDown" should be all lowercase when used with DOM events, not Widget events. Try:

 dojo.connect(dojo.byId("workpic"), "onmousedown", workpicDown); 

In the documentation:

Note on event names: Event names are now lowercase, except in special cases (for example, some Mozilla DOM events). Dojo will add "on" to your event name if you leave it (for example, 'click' and 'onclick' are the same before dojo). This differs from the Widget Event in the sense that Digit uses mixedCase to avoid potential conflicts.

+7
source

This is probably a problem with the execution context. Try using parry:

 dojo.connect(dojo.byId("workpic"), "onMouseDown",window, "workpicDown"); window.workpicDown = function() { alert("mousedown"); } 
0
source

Source: https://habr.com/ru/post/1345217/


All Articles