Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid displaying """ instead of quote marks? [closed]

Tags:

html

unicode

I have a PC running Windows 7. Surfing the web, I see plenty of normal quotation marks (", ') around. But occasionally, I'll see it written out as its HTML entity like this: ". I frequently see it on well-designed, big budget websites whose designers should know what they're doing, like IGN or CNN.

I'm curious as to why I'm seeing this, and if there's something wrong with my browser or computer. But my real question is this: is there a way to prevent special characters from appearing as HTML entities when other people, especially with older systems, view my website?

Generally speaking, what kind of code could cause this problem to arise, and how can it be prevented?

like image 913
Jeff Caros Avatar asked Oct 23 '25 17:10

Jeff Caros


1 Answers

It's possible that they were using JQuery's text() function instead of the html() function. That would cause the " to be shown rather than an actual quotation mark. The reason for this is because text() adds escape characters so that whatever is passed into it will be shown exactly the same when view on a web page (see below).

We need to be aware that this method escapes the string provided as necessary so that it will render correctly in HTML. To do so, it calls the DOM method .createTextNode(), [which] does not interpret the string as HTML. (Source: http://api.jquery.com/text)

The escape character &amp is probably what was added to the front of quot; by text() which would cause it to be displayed as "

like image 65
Miguel Magallanes Avatar answered Oct 26 '25 07:10

Miguel Magallanes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!