<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
</ul>
<script type="text/javascript">
function selectElementText(element) {
var range;
if ("selection" in document) {
range = document.selection.createRange();
range.moveToElementText(element);
range.select();
} else {
range = document.createRange();
range.selectNodeContents(element);
var sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}
window.onload = document.onmouseup = function () {
selectElementText(document.getElementsByTagName("li")[2]);
};
</script>