Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript select text in element

// Select text in element 'elm'
const elm = document.getElementById('elm');

// Clear any current selection
const selection = window.getSelection();
selection.removeAllRanges();

// Select paragraph
const range = document.createRange();
range.selectNodeContents(elm);
selection.addRange(range);
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #select #text #element
ADD COMMENT
Topic
Name
9+6 =