0

How to escape HTML strings with jQuery?

var someHtmlString = "<script>alert('hi!');</script>";

var escaped = $("<div>").text(someHtmlString).html();

console.log(escaped);
RUN
add comment
Suggest a different solution or add another example