Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I sanitize this string? (preferably in JQuery)?

I have a webpage where people type stuff into a text box, and it displays that text below them. That's it. There is no server side.

Let's say someone types <script src="blah">hello</script>

I want to display that as text. Not as a script, of course. How can I do that (all in javascript)?

I want to display the entire text. Don't stip the tags out.

like image 899
TIMEX Avatar asked Apr 30 '11 07:04

TIMEX


1 Answers

$('div.whatever').text($('input.whatever').val());

That'll convert things to HTML entities, so they're displayed as they were typed, and not treated as markup.

like image 71
David Fells Avatar answered Sep 27 '22 17:09

David Fells