JQuery preventDefault() is stopping subsequent function
I am using the preventDefault function to stop my form from submitting. This is working fine, however following that function I have a onClick function which is no longer working.
Strangely, before the onclick function I do have a simple div centering function wh开发者_JAVA技巧ich is working even following the form preventDefault.
Edit: I found the issue, the onclick function was for an item that was loaded via ajax in the first function. so the selector was probably not finding it
Below is my code:
// Submit zip code
$("#get_zip").submit(function (zip)
{
//Send zipcode
$.ajax({
type: "POST",
url: "ajax_calls.php",
data: "zip="+$('#zip').val()+"&send_zip=true",
success: function(listing){$("#wrapper").html(listing); $("#lightbox,#welcome").fadeOut(300);},
error: function(){alert(3);$("#error").text("Could not retrieve posts").fadeIn(300).delay(900).fadeOut(300)}
});
//Stop form submission action
zip.preventDefault();
});
//Center item box
$("#item").centerInClient();
//When clicking an item row
$("tr.item").click(function()
{
// Get item id from selected row id
var id = $(this).attr('id');
//Fill item box with item details
$.ajax({
type: "POST",
url: "ajax_calls.php",
data: "id="+id+"&get_item=true",
success: function(r){$("#item_detail").html(r); $("#lightbox, #item").fadeIn(300);},
error: function(){alert(2);$("#error").text("Could not retrieve posts").fadeIn(300).delay(900).fadeOut(300)}
});
});
Any Help on this would be very much appreciated.
Many thanks
Try changing:
zip.preventDefault();
to:
return false;
I think that preventDefault()
is bubbling up and canceling your click handler.
精彩评论