Welcome to WebmasterWorld Guest from 54.145.44.134

Forum Moderators: open

Message Too Old, No Replies

Jquery not working after add or remove on a table

     

andrewsmd

12:11 am on Jan 11, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I have some buttons that I call ajax with.

Basically I do this

$.ajax(
{ url: url,
data: data,
dataType: "json",
type: "POST"
}).always(function(d){CheckHoursStatus(d, action);});
Then in CheckHoursStatus, I either add rows to a table or remove rows from a table based on the action something like this

//this function takes in a status
//if it's an error, it shows the div, otherwise it adds the data
function CheckHoursStatus(d, action){

if(action == "AddHours"){


$("#hoursTable > tbody").append("<tr id='hoursRow" + d.id + "'><td>"+ $("#dayOperation").val() + "</td><td>" + startDate.toLocaleTimeString() +
"</td><td>" + endDate.toLocaleTimeString() + "</td>" + btn + "</tr>");
}

$("#addHoursOutput").fadeIn("medium");
setTimeout("HideDiv('addHoursOutput')", 5000);
}//if action == AddHours
else if(action == "DeleteOperationHours"){

$("#hourRow" + d.rowid).remove();
}//else if
They both work if you only do one. I.e if you just add all the time, the rows get added. If you remove, the rows get removed. However, as soon as you add a row then remove, nothing happens and vice versa. Any ideas why?

Fotiman

4:45 am on Jan 11, 2014 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Haven't looked too closely, but I do notice that your add creates a tr with id "hoursRow" + d.id, while your remove is removing something with id "hourRow" + d.rowid (note, no "s" in that one).