text selection problems

text selection problems

I have a table where the tbody is dynamically built on load.  I have a live event to disable text selection (for posting sake, I stripped out the x-browser support for text selection):

This table is editable, meaning I have an event to swap in a input box into the table cell.  What I want is to keep the table contents unselectable (I have an excel like cell selection in place instead), but I need the input box text selectable, and for the life of me I cannot get it to work.  It's either the td's are entirely unselectable, or entirely selectable, I can't seem to get the input boxes to be the exception.

I've tried many combinations of the second line, what's displayed now was my last attempt.  Are there any suggestions on how to do this?  The input boxes are added and removed, so there is only ever one input box existing on the table.

Is there anyway to turn off text selection on all the table cells excluding any input boxes in those table cells?

  1. $(function(){
  2. $.extend($.fn.disableTextSelect = function() {
  3. $(this).live('selectstart',function(){return false;});
  4. });
  5. $(".mytable th").disableTextSelect();
  6. $(".mytable td input:not(input[type=text])").disableTextSelect();
  7. });