0

i want to access the object inside the success function of $(obj).load(); like this :

$('.target').load('some url',function(){
    $(this).addClass('ajaxLoaded');
});

to use it in $.ajaxSetup like this :

$.ajaxSetup({
   success : function(){
      $(this).addClass('ajaxLoaded');
   }
});

but can't do that $(this) return the XHR elemnt

Mehdi
  • 683
  • 5
  • 16
  • 1
    save `$(this)` to a `var self` outside your ajax request and reference that later in your `success` callback – bruchowski Oct 15 '14 at 07:37
  • 1
    Why do you need to do this with `$.ajaxSetup()`? That will fire for other types of AJAX calls that aren't `.load()`, so they don't have a target element. – Barmar Oct 15 '14 at 07:39

1 Answers1

0

Notice: $.ajaxSetup.succes will be executed before the function within load() is executed.

So, the target element is not yet known (Maybe it is known somewhere, but I can't find it).

I think the use of $.ajaxSetup is not the right tool for what you are trying to do.

Emmanuel Delay
  • 3,619
  • 1
  • 11
  • 17