Reputation: 23
how do I apply CSS to an element AFTER the element has been loaded using .load()? Here a dummy version of what I'm working with.
$(document).ready(function(){
$("a.link").on("click", function() {
var Selected = $(this).attr("ID");
$("#container").load(Selected + ".php");
$("#box").css("background-color", "red");
return false;
});
});
Jquery loads #box into #container as intended using the .load() function, but the line with .css() doesn't work. When I click on the a.link to trigger the events, #box's background color turns red for a split second then reverts back. Anyone know how I can keep it red?
Thanks!
Upvotes: 2
Views: 630
Reputation: 121998
Load function have a callback. Use it.
$("#container").load(Selected + ".php", function(){
$("#box").css("background-color", "red");
});
Upvotes: 2