I have a piece of jQuery code as follow. When the button with id some_button is clicked, it gets some data (which is HTML code) from an url and then put the HTML it gets into some_div. The HTML it gets contains some buttons with class run and I want this buttons to be triggered automatically. With the following code, the run buttons are never trigger automatically when some_button is clicked for the first time, but works when it's clicked the second time. Another strange thing I notice is, when I use Chrome break points to step through the code, I find that it executes $(".run").trigger("click"); before executing $("#some_div").empty(); and $("#some_div").append(data.info);. Why is it executed in this order?
$("#some_button").click(function()
{
//some code here
$.get("/some_url", function(data){
$("#some_div").empty();
$("#some_div").append(data.info);
});
$(".run").trigger("click");
});