Linked Questions
95 questions linked to/from Escaping HTML strings with jQuery
38
votes
3
answers
72k
views
Escape HTML using jQuery [duplicate]
I came up with a hack to escape HTML using jQuery and I'm wondering if anyone sees a problem with it.
$('<i></i>').text(TEXT_TO_ESCAPE).html();
The <i> tag is just a dummy as jQuery ...
12
votes
9
answers
82k
views
Is there an easy way to convert text into HTML in JavaScript? [duplicate]
Possible Duplicate:
Escaping HTML strings with jQuery
JavaScript/jQuery HTML Encoding
For example, if I wanted to show the user the string x < 3 in HTML I would need to replace the < ...
-3
votes
1
answer
8k
views
how to replace &,<,> in javascript [duplicate]
In javascript how it's possible to replace all occurrence of &,<,> in a string
I tried this
var str="<>&";
str.replace("&","&").replace("<","<").replace(">...
0
votes
1
answer
3k
views
Convert HTML Entities using JavaScript (RegExp) [duplicate]
I wrote following code:
function convert(string) {
var before = '&';
var after= '&';
var pattern = new RegExp(before, 'g');
return string.replace(pattern,after);
}
convert("Dolce ...
-4
votes
3
answers
5k
views
Javascript: print html as plain text [duplicate]
I'm trying to print plain html from javascript and can't figured out how to do so.
Example:
$('#elem').html('This is a normal string'); // --> This is a normal string
$('#elem').html('This <b&...
5
votes
3
answers
142
views
display html as text [duplicate]
In my game, I changed the list of players from canvas to html, due to which a vulnerability appeared that any player can give himself a name into which he can insert js code, for example, <script&...
0
votes
0
answers
143
views
escape '<' inside <tr> tag in javascript [duplicate]
I have a field Value for segmentations as <Value TBD>, which is not getting printed in the HTML table.
This is the way I'm trying to populate the value:
if($("th[data-field='rating']").get(0)...
3551
votes
32
answers
2.0m
views
pretty-print JSON using JavaScript
How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
386
votes
17
answers
448k
views
Can I escape HTML special chars in JavaScript?
I want to display text to HTML by a JavaScript function. How can I escape HTML special characters in JavaScript? Is there an API?
297
votes
18
answers
408k
views
jQuery: Best practice to populate drop down?
The example I see posted all of the time seems like it's suboptimal, because it involves concatenating strings, which seems so not jQuery. It usually looks like this:
$.getJSON("/Admin/GetFolderList/"...
218
votes
18
answers
261k
views
What is the HtmlSpecialChars equivalent in JavaScript?
Apparently, this is harder to find than I thought it would be. And it even is so simple...
Is there a function equivalent to PHP's htmlspecialchars built into JavaScript? I know it's fairly easy to ...
406
votes
6
answers
708k
views
Which characters need to be escaped in HTML?
Are they the same as XML, perhaps plus the space one ( )?
I've found some huge lists of HTML escape characters but I don't think they must be escaped. I want to know what needs to be escaped....
156
votes
9
answers
258k
views
Defining a HTML template to append using jQuery
I have got an array which I am looping through. Every time a condition is true, I want to append a copy of the HTML code below to a container element with some values.
Where can I put this HTML to re-...
130
votes
13
answers
193k
views
Fastest method to escape HTML tags as HTML entities?
I'm writing a Chrome extension that involves doing a lot of the following job: sanitizing strings that might contain HTML tags, by converting <, > and & to <, > and &, ...
79
votes
7
answers
220k
views
Sanitizing user input before adding it to the DOM in Javascript
I'm writing the JS for a chat application I'm working on in my free time, and I need to have HTML identifiers that change according to user submitted data. This is usually something conceptually shaky ...