0
document.getElementById('analyseArticleBody').addEventListener('selectionchange', () => {
  console.log('hello')
  this.doubleClick()
})    

I want to know if any word is selected inside this section

Penny Liu
  • 15,447
  • 5
  • 79
  • 98

2 Answers2

0

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
ariel
  • 15,620
  • 12
  • 61
  • 73
0

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

Alejandro
  • 413
  • 3
  • 9
  • selectionstart don't meet my requirement, as it is fired whenever the selection starts..I want it when one is finished with the selection.Link helped me though.Thanks. – abhi matta Apr 06 '20 at 13:45