user823527
user823527

Reputation: 3712

Get page element text without html tags but keep linebreaks

I want to get text from elements on a page. I don't want the html tags but I want the linebreaks. If I do a $('#element').text() the linebreaks are removed. What is the way to keep the paragraphs from the element without the html tags?

Upvotes: 2

Views: 797

Answers (1)

jimw
jimw

Reputation: 2598

A quick and dirty solution would be to extract the HTML, replace all <p>, </p> and <br> tags with certain strings, then transform the HTML into text using jQuery's .text, then replace those certain strings with \ns.

This is far from a perfect solution, but it might be enough for your case.

Upvotes: 1

Related Questions