Basically I just need the effect of copying that HTML from browser window and pasting it in a textarea element.
For example I want this:
<p>Some</p>
<div>text<br />Some</div>
<div>text</div>
to become this:
Some
text
Some
text
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.
If that HTML is visible within your web page, you could do it with the user selection (or just a
TextRangein IE). This does preserve line breaks, if not necessarily leading and trailing white space.UPDATE 10 December 2012
However, the
toString()method ofSelectionobjects is not yet standardized and works inconsistently between browsers, so this approach is based on shaky ground and I don’t recommend using it now. I would delete this answer if it weren’t accepted.Demo: http://jsfiddle.net/wv49v/
Code: