Prototype to JQuery - how to access originator of event

Posted by ciaranarcher on Stack Overflow See other posts from Stack Overflow or by ciaranarcher
Published on 2010-05-07T20:53:41Z Indexed on 2010/05/07 20:58 UTC
Read the original article Hit count: 279

Hi there

I'm coming from a Prototype background and looking into JQuery. I'd like to know the 'right' way to do attach a click event to a bunch of elements, but then know in the event handler which one of my elements was clicked.

I've come up with the following:

MYNS.CarouselHelper.prototype.attachImgHandlers = function () {

  $j(".carouselItem").bind("click", this, function(e){ e.data.openCarouselImage(e) });

}

I then have the following in my event handler:

MYNS.CarouselHelper.prototype.openCarouselImage = function(e) {

    var img = e.currentTarget;
    // Do stuff to the image element

};

Is this 'right'? It feels wrong to me as I am used to explicitly passing the element to the event handler in Prototype as I loop through an array of elements.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about prototype

Related posts about jQuery