tags:

views:

75

answers:

3
A: 

does the statically loaded #fav div wrap all #submits, or just one? i assume the issue is that your delegating it to an object that isn't high enough on the dom. try replacing #fav with body, or some wrapper element.

additionally, as commented above, you should not use ids more than once on a given page, so a class .submit would be preferable.

$('body').delegate(".submit", "click", function() {

    var favid = $("input#favid").val();
    var favsave = 'favid=' + favid;
    $.ajax({
      type: "POST",
      url: "fav.php",
      data: favsave,
      success: function() {
        $('#fav').fadeOut(100);
      }
    });
    return false;

});

you'll probably need to add some context to those jquery selectors as well.

nathan gonzalez
@JacobM, edited to include that, though if you were really going to nitpick, we should also make sure that the input#favid is either unique or changed to a class as well. also, i'm making the assumption that even the #fav element's id is not unique, so that should probably be a class as well
nathan gonzalez
+1  A: 

My first guess would be that this is caused because you're trying to add multiple #submit elements. Element IDs are unique and should not be used more than once. I'd suggest switching to a submit class and trying again with...

$('#fav').delegate(".submit", "click", function() {

You should also switch your usage of #favid.

BBonifield
A: 

Which part of the page is being dynamically generated? If the element with ID of #fav is being dynamically generated then it won't work. You'll need to delegate the event handler to an element that exists on the page at the time the event is bound.

More info, preferably the HTML markup in question? :)

John Strickler