ppseprus
ppseprus

Reputation: 548

Is it possible to pass '$(this)' on to a delegated user function in jQuery?

function myfunc() {
  alert($(this));
}

$("#SELECTOR").delegate("SELECTOR","click",myfunc);

This is about clicking on different images, therefore, I'd really love to use the $(this) variable in my user function.

Is that possible? Is there any workaround?

Upvotes: 1

Views: 76

Answers (1)

lukeocom
lukeocom

Reputation: 3243

Yes. The syntax for delegate is:

$('#container').delegate('selector','event',function(){
//code to respond to event
});//end delegate

which is pretty much what you already have,..

A working example which includes the method you are attempting is here - http://jsfiddle.net/E9dgU/5/

Upvotes: 1

Related Questions