urfalizeyno urfalizeyno - 1 year ago 83
Javascript Question

How to parse text

I get text field in the document. I get it by

But sometimes text field includes
<em> </em>
<cite> </cite>
I want the raw text.

I get the text by their id such as;

It returns me;

further cholesterol transport <em class="a-plus-plus"> Large luteal cells </em> produce <em class="a-plus-plus">more</em>


<cite>Sodium bicarbonate</cite> is a white solid that

How can I get the raw text as;

further cholesterol transport Large luteal cells produce more

Sodium bicarbonate is a white solid that

Should I parse the text when I get by their id, or should write a regex that detects
tags and gets the text inside these tags. What is the best solution for this problem? Is there any solution offered for this type of parsing?

Answer Source

The jQuery method .text() will get the text content of the selector, which will exclude HTML.


Similarly in plain JavaScript the .textContent property will also do this by not parsing as HTML.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download