Azeem
Azeem

Reputation: 2924

HTML Rich-Text to Plain-Text by TextArea control

I am reading some rich-content text from server and trying to display it in a grid in plain-text format. That's where i got this problem. I am not able to get rid of html styling tags. I dont want to write some dirty JS/Jquery code to remove HTML styling tags as it is not possible to handle all of the tags. So I thought to do a trick and created a hidden textarea on HTML page:

<textarea name="textarea" id="temp_desc" rows="10" cols="50" style="visibility: hidden"></textarea>

In JS, when I read data from server, I write it in this textarea and then read it back so that all html tags should strip down but It is not working. The html tags themselves get written in this textarea:

document.getElementById("temp_desc").value = Description;
Description = document.getElementById("temp_desc").value;

Any other suggestions how can i make this work?

Thanks.

Upvotes: 1

Views: 4183

Answers (1)

Azeem
Azeem

Reputation: 2924

I solved this problem by using DIV instead of textarea and JQuery method .text().

HTML:

<div id="temp_desc" style="visibility: hidden"></div>

JS:

$("#temp_desc").html(Description);
var descHiddenDIV = document.getElementById("temp_desc");
var temp_description = $(descHiddenDIV).text();

After executing above JS code, temp_description contains plain-text.

Upvotes: 1

Related Questions