Allen S
Allen S

Reputation: 53

Is there any event fires after $("#").load() is completed in Jquery?

I want to change some partial-view html code after the partial-view is loaded by this function

$("#myRootElement").load("MyAction?Parameter=" + value);

I saw inside the JQuery source code, there is a

$("#myRootElement").innerHtml = "MyPartialViewHtmlCode"

But I didn't find any event fires after this inner html is set. I want to fires a event after this here is what I have tried.

$("#myRootElement").on('load', function(){
  // My code.
})

$("#myRootElement").load('action?parameter=' + value);

It doesn't work at all. The break point never been hit.

Upvotes: 0

Views: 51

Answers (2)

Peter-Yu
Peter-Yu

Reputation: 191

You can see this page, there is a callback param. Use like this

$("#myRootElement").load("MyAction?Parameter=" + value, function() {
  alert( "Load was performed." );
});

Upvotes: 1

digital-pollution
digital-pollution

Reputation: 1074

load provides a callback you can use

$("#myRootElement").load('action?parameter=' + value, function() {
  // load complete  do stuff
});

Upvotes: 1

Related Questions