misima
misima

Reputation: 423

How to use $(this) in $(this), on Jquery

$('.element').each(function(){
  $(this).load('file.php',function(){
    $(this).show(); // this row is not working
  });
});

or

$('.element').each(function(){
  setTimeout(function(){
    $(this).show(); // this row is not working
  },1000);
});

Upvotes: 1

Views: 1126

Answers (3)

Pawka
Pawka

Reputation: 2576

You can try use jQuery.proxy() transfer object inside to other scope.

Upvotes: 0

shankhan
shankhan

Reputation: 6571

you need to save it in a variable or pass into inner function

$('.element').each(function(){
  var outerObj = this;
  $(this).load('file.php',function(){
    $(outerObj).show(); // this row is not working
  });
});

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

$('.element').each(function(){
    var $this = $(this);
    $this.load('file.php',function(){
        $this.show();
    });
});

or:

$('.element').each(function() {
    var $this = $(this);
    window.setTimeout(function() {
        $this.show();
    },1000);
});

Upvotes: 4

Related Questions