1

When a user highlights a section of the web page being, how do I get access to the piece of html or text that a user has selected.

Looks like the jquery select only works on input elements.

Basically what is the easy way to access parts where the css3 ::selection selector has taken effect.

smartnut007
  • 6,324
  • 6
  • 45
  • 52
  • Possible duplicate: http://stackoverflow.com/questions/5379120/jquery-get-the-highlighted-text – kei May 07 '12 at 04:40
  • I think there is already a solution posted http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse Try to observe others question and answers first then only post the question. – mesimplybj May 07 '12 at 05:31

1 Answers1

0

you can try:

document.getSelection()

var text = '';
if (window.getSelection)
    {
        text = window.getSelection();
    }
    else if (document.getSelection)
    {
        text = document.getSelection();
    }
    else if (document.selection)
    {
        text = document.selection.createRange().text;
    }
    else return;
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164