Return to Snippet

Revision: 56929
at April 25, 2012 07:10 by charliefmoran


Initial Code
function selectText(element) {
    var doc = document;
    var text = doc.getElementById(element);    

    if (doc.body.createTextRange) { // ms
        var range = doc.body.createTextRange();
        range.moveToElementText(text);
        range.select();
    } else if (window.getSelection) { // moz, opera, webkit
        var selection = window.getSelection();            
        var range = doc.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
    }
}

Initial URL
http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse

Initial Description
cross-browser way to select all text in a form element, via Jason on Stack Overflow

Initial Title
select text in form element

Initial Tags
form, text

Initial Language
JavaScript