Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

select not input elements text JS

document.querySelector('button').addEventListener('click', function(){
    var range = document.createRange();
    var selection = window.getSelection();
    range.selectNodeContents(document.querySelector('p')); // the element want to select it's content
    
    selection.removeAllRanges();
    selection.addRange(range);
});

// https://developer.mozilla.org/en-US/docs/Web/API/range/selectNodeContents
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #select #input #elements #text #JS
ADD COMMENT
Topic
Name
9+1 =