how to select text javascript
function selectText(node) {
node = document.getElementById(node);
if (document.body.createTextRange) {
const range = document.body.createTextRange();
range.moveToElementText(node);
range.select();
} else if (window.getSelection) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(node);
selection.removeAllRanges();
selection.addRange(range);
} else {
console.warn("Could not select text in node: Unsupported browser.");
}
}
const clickable = document.querySelector('.click-me');
clickable.addEventListener('click', () => selectText('target'));
Also in JavaScript:
- react native vs flutter
- js-cookie
- smooth scrolll to id js
- JSONDecoder
- javascript test if it is an array
- how to get the number of days in a month in javascript
- bodyparser express
- minify css package.json
- event exit fullscreen
- find all subsets of an array javascript
- implement subscript operator js
- check server command discord.js
- lodash map
- how to stop the node server from running
- javascript not working on rails app
- javascript double question mark
- JS get viewport width
- javascript palindrome
- this.setstate is not a function in react native
- $(getJson) returning error
- webpack react proxy not working
- fillstyle
- jquery check if element has class starting with
- js loop over array of objects extract value