Here is my jQuery using delegate and ajax:
$(".tweets").delegate("#fav #submit", "click", function(){
var favid = $("#fav input#favid").val();
var favsave = 'favid=' + favid;
alert(favsave);
$.ajax({
type: "POST",
url: "fav.php",
data: favsave,
success: function() {
$('#fav').fadeOut(100);
}
});
return false;
});
The HTML:
<div class='tweets'>
<ul class='entries'>
<li>
<form id='fav' method='post' class='favo' action=''>
<input style='display: none;' type='text' name='fav' id='fav' value='".$row["tweetid"]."' />
<input type='submit' value='Add to Favorites' name='submit' id='submit' />
</form>"
</li>
</ul>
</div>
There is another set of Ajax on the page that is constantly adding to the .entries list, these records that get appended pickup the click function, so that when I click on them the Alerts are shown but the Ajax part of the function doesnt work.
Any ideas? Would .live be better?