Reputation: 1975
Problem:
By Rosa Golijan <br/><br/>The next time someone interrupts you to proclaim that "retweet"
or "woot" aren't actual words, laugh in his or her face and point to a copy of the
Concise Oxford English Dictionary. <br/> <br/>Yes, one of the main authorities on the
English language is officially acknowledging some of the silly terms we've been using
lately. <br/> <br/>The twelfth edition of the Concise Oxford English Dictionary
includes over 400 new words — many of which are related to social media and technology.
According to the folks behind the esteemed reference text, these additions "are just
carrying on the tradition of a dictionary that has always sought to be progressive and
up to date."
Question: I'm having a hard time finding an easy way for my dynamic jquery code to render the html tags as html, rather than simply displaying the text with the html break tags as part of the text. The text on the database/server-side originally had newlines in it, i then converted those new lines to (br/) tags for html formatting. Now as the text is returned in json format, the html tags are displayed literally.
Now i'm using jquery .html() and .text() for testing this, but still the html tags are displayed as part of the text.
Thanks for the suggestions. I will try them out when i get a chance. I'm using Salesforce and it has some built in functionality for handling these issues with it's proprietary components, i was just trying to get away from using them as they are not as dynamic as i need them to be. However i was able to force them to be a little more dynamic.
Also, JS Fiddle is something i've never heard of before. Ive been carrying two laptops around with me to work, one with dreamweaver and one being the machine with all my other necessary software. Not having dreamweaver to test jquery was becoming a problem, i had no idea there was a cloud-based tool that would allow me to do the same things i do in dreamweaver. Thanks alot for that suggestion MrChief, that will really come in handy!
Are there any other tools you could hip me to?
Upvotes: 0
Views: 259
Reputation: 76218
Is your string properly escaped? I see this working for me: http://jsfiddle.net/mrchief/BekAx/1/
<div id=myDiv></div>
var str = 'By Rosa Golijan <br/><br/>The next time someone interrupts you to proclaim that "retweet" or "woot" aren\'t actual words, laugh in his or her face and point to a copy of the Concise Oxford English Dictionary. <br/> <br/>Yes, one of the main authorities on the English language is officially acknowledging some of the silly terms we\'ve been using lately. <br/> <br/>The twelfth edition of the Concise Oxford English Dictionary includes over 400 new words — many of which are related to social media and technology. According to the folks behind the esteemed reference text, these additions "are just carrying on the tradition of a dictionary that has always sought to be progressive and up to date."';
$('#myDiv').html(str);
Upvotes: 0
Reputation: 322502
"...i then converted those new lines to (br/) tags for html formatting. Now as the text is returned in json format, the html tags are displayed literally."
I'll assume you have (br)
in your question because you were't sure how to make the tags show up properly.
If that's the case, then you're probably using .text()
to add the new content.
Use .html()
instead.
If you are already using .html()
, then give this a try:
$('.some_container').html( $('<div>').html(response_text).text() );
Upvotes: 1