1function selectElementContents(el) {
2 var body = document.body, range, sel;
3 if (document.createRange && window.getSelection) {
4 range = document.createRange();
5 sel = window.getSelection();
6 sel.removeAllRanges();
7 try {
8 range.selectNodeContents(el);
9 sel.addRange(range);
10 } catch (e) {
11 range.selectNode(el);
12 sel.addRange(range);
13 }
14 } else if (body.createTextRange) {
15 range = body.createTextRange();
16 range.moveToElementText(el);
17 range.select();
18 }
19}