I found this page:
https://developer.mozilla.org/en/DOM/Selection which is the DOM referenece for FF (I think), and I made this example which works in FF:
Code:
<script type="text/javascript">
function FFSelect(node)
{
r = document.createRange();
r.selectNodeContents(node);
window.getSelection().removeAllRanges();
window.getSelection().addRange(r);
}
</script>
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">Code:</div>
<pre name="codearea" class="alt2" dir="ltr" style="
margin: 0px;
padding: 0;
border: 1px inset;
width: 900;
height: 400px;
text-align: left;
overflow: auto">This is some code to select</pre><input type="button" value="Highlight Code" onClick="javascript:this.parentNode.children[1].focus();FFSelect(this.parentNode.children[1]);">
</div>
Of course it won't work in IE, so I think what you really need is one Select function that tests for which functions exists and does the appropriate thing. Sorry I don't have time to work it all out just now.