I got this jQuery code which is working just fine. Except on element I load after the page is ready.
$('.reply').click(function(){
ele = $(this).attr('title');
$('#'+ele).load('ajax/form_post.php');
$('#'+ele).show();
return false;
});
$('.add_com form').submit(function(){
ele = $(this);
$.post('ajax/com.php',
{ info : ele.parents('.add_com').attr('title'),
texte : ele.find('textarea').val(),
},
function(data) {
if(data == 'xxxx'){
alert('erreur');
}
else{
ele.parents('.add_com').append(data);
}
});
return false;
});
after I loaded the form clicking on the add_com form doesn’t work. It works on form already loaded though…
Check out JQuery’s live method. Using this allows you to apply your code to anything it sees in the DOM on page load or in the future.