I can use the following code to get selected text:
text=window.getSelection(); /// for Firefox
text=document.selection.createRange().text; /// for IE
But how can I get the selected Html, which includes the text and html tags?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In IE <= 10 browsers, it’s:
As @DarrenMB pointed out IE11 no longer supports this. See this answer for reference.
In non-IE browsers, I just tried playing with this… this seems to work, WILL have side effects from breaking nodes in half and creating an extra span, but it’s a starting point:
Unfortunately, I can’t seem to put the node back as it was (since you can be pulling half the text from a span, for instance).