Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Jquery not working after add or remove on a table

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0

I have some buttons that I call ajax with.

Basically I do this

{ 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>");

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?
4:45 am on Jan 11, 2014 (gmt 0)

Senior Member from US 

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

joined:Oct 17, 2005
posts: 4988
votes: 12

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).