Get clicked word using pure Javascript

On browser, if we want to get the clicking word we can use following Javascript: var captureWordOnClick = function(containerEl, callback) { containerEl.addEventListener( click , function (event) { // Get the mouse position relative to the clicked element const x = event.clientX; const y = event.clientY; // Get caret position at the point of click const caretPosition = [ ]