The function below toggles the highlight on a cell when a user clicks the cell.
It works well if the cells are there when the document loads. However, it does not work on newly appended cells.
What could I change to make it work for new cells?
$(function () {
var isMouseDown = false,
isHighlighted;
$("#tablegrid td.nohighlight")
.mousedown(function () {
isMouseDown = true;
$(this).toggleClass("highlighted");
isHighlighted = $(this).hasClass("highlighted");
return false; // prevent text selection
})
.mouseover(function () {
if (isMouseDown) {
$(this).toggleClass("highlighted", isHighlighted);
}
})
.bind("selectstart", function () {
return false;
})
$(document)
.mouseup(function () {
isMouseDown = false;
});
});