Fnord Nase wrote:
I guess my question is: is it possible to unselect text?
Yes you can, using Ranges and clearing the selection. See below (tested
IE7, FF2 and Opera 9).
---
<div ondblclick="clearSelection()">Hello, world!</div>
<script type="text/javascript">
function clearSelection() {
var sel ;
if(document.selection && document.selection.empty){
document.selection.empty() ;
} else if(window.getSelection) {
sel=window.getSelection();
if(sel && sel.removeAllRanges)
sel.removeAllRanges() ;
}
}
</script>
---
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_textrange.asp>
<URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html>
Note that IE supports an onselectstart attribute; defining
onselectstart="return false" prevents any selection on the element.
However, you do not seem to want to prevent the selection in every case,
only when you have your double click behavior, so it might not be
appropriate to use it (after all, the user may legitimately want to
select some part of the element, for copy-pasting).
HTH,
Elegie.