Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - parent "this"

$('form').each(function(){
  var form = this;
  $('a', this).click(function(){ form.submit(); });
});

Is there any way I can get the parent (this) element inside of that click function, without using a intermediate variable? I was thinking that maybe there's a keyword I'm not aware of that lets you do it.

In the $.ajax function there's a context paramters which allows you to do something like this.

like image 763
Alex Avatar asked Jun 08 '11 22:06

Alex


1 Answers

No, you have done it the best way. Convention suggests using that:

var that = this;
$('a', this).click(function(){ that.submit(); });
like image 169
glortho Avatar answered Oct 19 '22 23:10

glortho