check where in text its selected javascript code example Example: get selected text js // Get highlighted text this way: window.getSelection().toString()