Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert plain text in to HTML

Tags:

jquery

text

I have a script with which at a certain point I'm getting HTML(data) with Ajax call. I have to turn this HTML in to plain text like this:

$("#div").text(data);

I now want to turn this around and make the text HTML again. I there an easy Jquery method of doing this? I tried:

$("#div").text(data).end().html();

No luck.

like image 492
Youss Avatar asked Feb 06 '13 21:02

Youss


People also ask

How do I change my Outlook email from plain text to HTML?

Change Default Email Format for Sending Messages Go to File > Options. In the Outlook Options dialog box, select Mail. In the Compose messages section, select the Compose messages in this format dropdown arrow and select either HTML, Plain Text, or Rich Text. Select OK to close the Outlook Options dialog box.


1 Answers

You would need to hold onto the original response to do this...

$("#hiddendiv").html(data);
$("#div").text(data);

Then you could get it back out...

var html = $("#hiddendiv").html();

Update based on comment...

You can remove that element before you display it...

var html = $(data);
$('#cookiediv', html).hide();
$('#div').html(html);

Where the cookie message has id="cookiediv" - you may need to adjust the selector to get to this div, but it is almost certainly possible to grab it.

like image 109
Fenton Avatar answered Oct 13 '22 18:10

Fenton