Javascript Function to Select Text (onclick)
Javascript Function Code to Select All Text Contained Within an Element, such as a DIV etc
Home
Short:
/* ------------------------------------------- select the text that occurs within [elem] you can pass [elem] to the function via document.querySelector() ------------------------------------------ */ function selectText(elem) { if (document.selection) { // IE var range = document.body.createTextRange(); range.moveToElementText(elem); range.select(); } else if (window.getSelection) { var range = document.createRange(); range.selectNode(elem); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); } }
source code home