tags being converted to & lt; br / & gt; "? I have HTML data stored in a database that I want to display as is. He continues to c...">

Why are my <br/"> tags being converted to & lt; br / & gt; "?

I have HTML data stored in a database that I want to display as is. He continues to convert tags
at &lt;br /&gt; whose behavior I do not want. I tried playing with javascript replacement, and yet I cannot convert it to plain HTML.

  var venueaddress = msg.result[0].venueaddress; var venueaddress2 = venueaddress.replace("[newline]", "<br />"); alert(venueaddress2); //shows <br /> $("#venueaddress").text(venueaddress2); //lets now display it on the browser <li><h3>Venue Address</h3><p><strong> <span id="venueaddress"></span> </strong></p></li> 

However, when it is displayed in the browser, it has <br /> and therefore there is no line break.

+6
source share
4 answers

Your problem with

 $("#venueaddress").text(venueaddress2); 

you should use

 $("#venueaddress").html(venueaddress2); 

The text will encode any html-character and display it in a range as encoded, html will not.

+7
source

&lt;br /&gt; == <br /> You just need to decode the output to return the original HTML.

Use javascript unescape function

+3
source

Presumably because when you embed it in the DOM, you embed it as text, not HTML.

Since you are not showing the code that you use for this, itโ€™s hard to say for sure or say that the best way to change it is, therefore, it expects HTML to be.

+2
source

Your html data will be "escaped". This prevents the <script> tag from being sent to people who suspect nothing of their browser.

Fix: first you need to determine if your problem is a โ€œbugโ€ or a โ€œfunctionโ€.

Escaping html is usually good. Especially if the only problem is the presentation.

For example, the job might be to insert newlines, not the br element.

0
source

Source: https://habr.com/ru/post/896915/


All Articles