Select Text in Element - Javascript

Select Text in Element - Javascript

code snippet

javascript
function SelectText(element_id) {
    var doc = document
        , text = doc.getElementById(element_id)
        , range, selection
    ;
    if (doc.body.createTextRange) {
        range = document.body.createTextRange();
        range.moveToElementText(text);
        range.select();
    } else if (window.getSelection) {
        selection = window.getSelection();
        range = document.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
    }
}

"Try to be a rainbow in someone's cloud"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.