Gary' Blog

Gary' Blog

Gary's Technical Blog

马上订阅 Gary' Blog RSS 更新: https://garymeng.com/feed/

Get clicked word using pure Javascript

Gary
2024年10月3日 16:19
Technical
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 = […]