Mo3z
Mo3z

Reputation: 2128

How to pass the element in dojo.connect

I am creating a widget in dojo that enlarges the thumbnail on mouse over.

The widget binds the mouseover event with all thumbnails in the constructor like this:

dojo.connect(imgTag, "mouseover", this, "_showImgPreview");

In _showImgPreview() I need the image on which mouse over event occurred. By doing above I am only getting the event and not the image.

How can I get the thumbnail on which event occurred in _showImgPreview()?

I know I can do like this but I am interested in knowing how can I do it using the method mentioned above.

var self = this;
dojo.connect(imgTag, "mouseover", function(e){
   self._showImgPreview(e, this);
});

Thank you in advance!

Upvotes: 1

Views: 117

Answers (1)

Craig Swing
Craig Swing

Reputation: 8162

e.target will be the imgTag.

If you are inside a class that is extending Widget, you can use

this.connect(imgTag, "mouseover", "_showImgPreview");

If you are not, you can use

dojo.connect(imgTag, "mouseover", dojo.hitch(this, this._showImgPreview));

Note: dojo/connect has been deprecated in favor of dojo/on

Upvotes: 2

Related Questions