john
john

Reputation: 87

Get innerHtml but remove unwanted tags

I want to know that how can i get innerHtml without the html tags. Only the text.

Upvotes: 1

Views: 4527

Answers (3)

DreadPirateShawn
DreadPirateShawn

Reputation: 8402

If you're not using jQuery (or even if you are), this link explores some of the different options (eg innerText vs textContent), along with how they differ between browsers:

http://www.davidtong.me/innerhtml-innertext-textcontent-html-and-text/

Basically, not all approaches work in all browsers, and some strip line breaks while others don't.

Upvotes: 5

defau1t
defau1t

Reputation: 10619

You could use the text() function instead:

Use $("your_element").text()

You can use also:

document.getElementById("your_element").textContent;

Upvotes: 2

gurch101
gurch101

Reputation: 2064

if you're using jquery, use $('myelem').text().

API Reference: http://api.jquery.com/text/

Upvotes: 5

Related Questions