Search code examples
javascriptinputmarkdownuser-input

How to get selected text from input field


Let's suppose I'm making some kind of markdown something like a stack-over-flow markdown. I want to get selected text from input and do some action with it

Reference

something like this!

Here The Selected Text is Hello


Solution

  • you can use

    window.getSelection().toString()
    

    it'll get the highlighted or selected text within the page