dblclick highlight feature for textarea double click a word in a textarea all the occurances of that work are highlighted e g double click the word once and you ll see all the words ingoring case show up red style body min height 300px high background color red tex position absolute width 100 height 100 margin 0 padding 0 font size 12pt font family courier line height 1 white space pre wrap style div style width 100 height 100px textarea ondblclick doselect oninput doupdate class tex id src Once not twice but once upon a time long ago lived a creature of magnificent power a creature so Do frogs like ice cream Do all cats prefer warm milk textarea div class tex style pointer events none id dst div div script function highlight str findWord className var regex new RegExp findWord gi var newInnerHTML str replace regex function matched return span class className matched span return newInnerHTML var src document getElementById src var dst document getElementById dst dst innerHTML src value function doselect console log doselect let word window getSelection toString console log word word let res highlight src value word high dst innerHTML res function doupdate dst innerHTML src value console log ready script
ea div class tex style pointer events none id dst div div script function highlight str findWord className var regex new RegExp findWord gi var newInnerHTML str replace regex function matched return span class className matched span return newInnerHTML var src document getElementById src var dst document getElementById dst dst innerHTML src value function doselect console log doselect let word window getSelection toString console log word word let res highlight src value word high dst innerHTML res function doupdate dst innerHTML src value console log ready script