I've been working on an editable table using the HTML5 attribute contenteditable
. Everything was going smoothly until I had an idea to highlight the cell that was just updated by adding a class called alert-danger
from Bootstrap.
Once a cell is successfully updated, data is sent back to the parent page to inform the result
div about the status. Currently, the status is displayed on top of the table, but I wanted to also add the class to the specific cell. So, I included
$("td[id="+cols3_key+"").addClass('alert-danger');
when the data is returned. I expected the latest cell to be applied with the alert-danger class, but unfortunately, it didn't work as intended. Here's my script:
Javascript
var message_status = $("#status");
$("td[contenteditable=true]").blur(function(){
var cols3_key = $(this).attr("id") ;
var value = $(this).text() ;
$.post('inc/ajax.php' , cols3_key + "=" + value, function(data){
if(data != ''){
$("td[id="+cols3_key+"]").addClass('alert-danger');
message_status.slideDown();
message_status.text(data);
//hide the message
setTimeout(function(){message_status.slideUp()},3000);
}
});
});
The question is: How can I modify this line to target the cell that was just processed?
$("td[id="+cols3_key+"").addClass('alert-danger');
Best Regards,