Reputation: 333
I am facing a problem with jquery. I have table in which i have multiple rows. When i click one of the rows (only once) i should send a post with jquery. The problem is i cant use the one() function for this, because the event happens for all the table cells. Here is the code:
$("#tabel_notificari").one("click", ".rand_notif td:last-child" ,function(e){
e.stopPropagation();
var idNotif=$(this).parent().attr("record");
$.post("../template/masa/gestionare_notificare.php",{id:idNotif, status:3}, function(data){
$(this).parent().prev(".spacer_2").remove();
$(this).parent().fadeOut(500);return true;});
});
Is anyone able to helpme with this problem? Thanks.
Upvotes: 0
Views: 48
Reputation: 26143
Use a variable outside the click event, and use on
instead of one
...
var clicked = false;
$("#tabel_notificari").on("click", ".rand_notif td:last-child" ,function(e){
e.stopPropagation();
if (!clicked) {
clicked = true;
var idNotif = $(this).parent().attr("record");
$.post("../template/masa/gestionare_notificare.php",{id:idNotif, status:3}, function(data){
$(this).parent().prev(".spacer_2").remove();
$(this).parent().fadeOut(500);
return true;
});
}
});
That will only allow the click code to run once, regardless of which cell is clicked.
Upvotes: 2