Mousedown on appended items : <p>The function below toggles the highlight on a cell when a user clicks the cell.</p>

<p>It works well if the cells are there when the document loads.  However, it does not work on newly appended cells.</p>

<p>What could I change to make it work for new cells?</p>

<pre><code>  $(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;
    });
});
</code></pre>
