cometta
cometta

Reputation: 35759

jquery click "this"

If do this

$this.find('div').click(customFunc); // inside customFunc , $(this) is a div

If do this

$this.find('div').keypress(
    function(e) {  
       customFunc();
    }
 );   // inside customFunc , $(this) is a window

I want when keypress is called, inside customFuc(), $(this) is div.

How to do that and maintain using function(e) for keypress?

Upvotes: 0

Views: 110

Answers (1)

Kevin B
Kevin B

Reputation: 95056

Use customFunc directly.

$this.find('div').keypress(customFunc);

Otherwise, you can apply a context to it with .call or .apply

$this.find('div').keypress(function(e){
    customFunc.call(this);
});

Upvotes: 2

Related Questions