Jquery Inside Dynamically Generated Element Doesn't Run
I have an index which shows a list of orders, each of wich calls a function (named dinamically with php when i brought the data from the db), to simplify i've reduced the function
Solution 1:
Ok, so doing more research I came upon the best answer for my case, I'll leave it here in case it helps someone:
In the content I generate in the AJAX call, I print the scripts like this, and obviously hide it with css:
<div class="javascript">
$("body").on("click","#btn4255",function(){
alert("Pedido 4255");
});
</div>
And then I execute this function every time the AJAX call is returned
$('.javascript').each(function() {
eval($(this).text());
});
I only evaluate strings I generate myself so in this case I think it's not unsafe to use eval().
Post a Comment for "Jquery Inside Dynamically Generated Element Doesn't Run"