js get element where text is being selected code example Example: get selected text js // Get highlighted text this way: window.getSelection().toString()