Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non Selectable Text for table rows

Status
Not open for further replies.

jimbojames5645

Programmer
Dec 12, 2003
36
US
I want to make a table where the text in the table rows is not selectable.
 
You will have to use several methods to get something that works cross-browser. I use this combination of CSS and JavaScript. For the CSS part, assign the class "unselectable" to the element:

Code:
.unselectable {
   -moz-user-select: none;
   -khtml-user-select: none;
   user-select: none;
}

and then using JS, add an onselectstart handler to it:

Code:
yourEl.onselectstart = function() { return(false); };

You could also use behaviours to sort out IE, instead of that JavaScript:

Code:
.unselectable {
   behavior: url(ieUserSelectFix.htc);
}

and then create this file, "ieUserSelectFix.htc":

Code:
<public:component lightweight="true">

	<public:attach event="ondocumentready" onevent="stopSelection()" />

	<script type="text/javascript">
	<!--
		function stopSelection() {
			element.onselectstart = function() { return(false); };
			element.setAttribute('unselectable', 'on', 0);
		}
	//-->
	</script>
</public:component>

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top