Entry
How do you deselect the current selection?
How do you deselect the current selection?
How do you deselect the current selection?
Feb 26th, 2001 09:09
Martin Honnen,
IE4+ and Mozilla M0.8 (so likely future NN6 releases too) can do that.
Here is an example:
<HTML>
<HEAD>
<TITLE>
delecting the current selection
</TITLE>
<SCRIPT>
function deselect () {
if (document.selection)
document.selection.empty();
else if (window.getSelection)
window.getSelection().removeAllRanges();
}
function selectElement (id) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.all[id]);
range.select();
}
else if (window.getSelection()) {
var range = document.createRange();
range.selectNodeContents(document.getElementById(id));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="selectElement('aP');">
<INPUT TYPE="button" VALUE="deselect selection"
ONCLICK="deselect();"
>
<P ID="aP">Kibology for all.</P>
All for Kibology
</BODY>
</HTML>