document.getElementById('analyseArticleBody').addEventListener('selectionchange', () => {
console.log('hello')
this.doubleClick()
})
I want to know if any word is selected inside this section
document.getElementById('analyseArticleBody').addEventListener('selectionchange', () => {
console.log('hello')
this.doubleClick()
})
I want to know if any word is selected inside this section
You can calculate the length of document.getSelection()
:
document.addEventListener('selectionchange', (ev) => {
var selection = document.getSelection().toString();
console.log(selection.length + " characters selected");
})
Test text
As noted on this other answer, this event only attaches to the document but you could use selectstart
for a specific element.
JavaScript selectionchange event for a particular element only