I’m using jQuery to put text into a div as follows:
$("#commentview").html(rowData.Text);
If, for example, rowData.Text is "I haven't seen this.", in IE the results show as:
"I haven't seen this."
However, in Chrome the ' shows properly.
"I haven't seen this."
Any ideas why this would be and if there is a work-around?
Thanks!
UPDATE
I was fooled by Chrome web developer tools. I had added a watch to rowData.Text and it was showing me "I haven't seen this.", so I thought that was what I was working with. But when I looked at the actual JSON response that populates rowData it had "I haven't seen this."
My guess would be that your data actually contains that
'and that Chrome turns it into a single quote automatically and IE doesn’t. So sanitize your text response on the server or normalize it on client before appending.As we can see here: http://james.padolsey.com/jquery/#v=1.6.2&fn=jQuery.fn.html jQuery doesn’t mess with escaping single quotes or something like that. In the end
.html()uses.innerHTMLso that is what you should look into to simplify the solution of your problem.Try
console.logging yourrowData.Textand see if it indeed contains'and then do something like the following:But what would be better is to solve this on the server side, as
'is not a valid HTML entity: https://stackoverflow.com/a/2083770/236135