Howard Fring
Howard Fring

Reputation: 305

Fire an event when .load() is ready

I load an other HTML page to this one and when it's ready I want to change the css of an element from that page. The problem is that the "changing" function triggers before the other page is loaded. So it does nothing.

$("#navbar").load("/other.html");


$("#otherPageElem").css({
   "background": "black",
   "color": "white"
});

Upvotes: 1

Views: 39

Answers (1)

charlietfl
charlietfl

Reputation: 171669

Use the complete callback of load()

$("#navbar").load("/other.html", function(){
  // new html exists now

    $("#otherPageElem").css({
       "background": "black",
       "color": "white"
    });

});

Upvotes: 1

Related Questions