0

I'm writing some javascript functions which allow a user to select rows using ctrl and shift. However, when a user clicks on a row sometimes the actual table data is highlighted, asif you were going to copy and paste a value over into a word document.

Is there any way i can make the data un-highlightable?

Tom
  • 369
  • 2
  • 6
  • 16
  • It sounds like you are setting the background on the element that is clicked, rather than on whatever table row contains it. If you show the relevant portion of your code, it would be easier to assist. – Anders Fjeldstad Feb 21 '11 at 12:01
  • Can you show us some of that code? – adarshr Feb 21 '11 at 12:02
  • Can't really put code in here as it's way too complicated. But, a user selects a row, this does colour the whole row element blue. If they hold down shift and then click on another row it starts to highlight the values asif i was going to copy and paste the table into excel (which is probably expected), so i need to turn off this default behaviour? – Tom Feb 21 '11 at 12:19

3 Answers3

0

You can try adding:

onselectstart="return false;"

to your table HTML.

If you are using Jquery:

$.fn.disableSelection = function() {
    $(this).attr('unselectable', 'on')
           .css('-moz-user-select', 'none')
           .each(function() { 
               this.onselectstart = function() { return false; };
            });
};
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
0

Refer - Prevent selection in HTML

Community
  • 1
  • 1
ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
0

I'm not sure there's a JavaScript solution but there is a partial css solution:

#my-table-id {
  -moz-user-select: none; /* for mozilla browsers */
  -webkit-user-select: none; /* for webkit browsers - safari, chrome */
}
meouw
  • 41,754
  • 10
  • 52
  • 69