Экранирование строк HTML с помощью jQuery

Поскольку вы используете escaped-characters jQuery, вы можете просто установить str свойство text элемента:

// before:
// 
text
var someHtmlString = ""; // set a DIV's text: $("div.someClass").text(someHtmlString); // after: //
<script>alert('hi!');</script>
// get the text in a string: var escaped = $("
").text(someHtmlString).html(); // value: // <script>alert('hi!');</script>

javascript

jquery

string

escaping

2022-11-10T04:04:50+00:00
Вопросы с похожей тематикой, как у вопроса:

Экранирование строк HTML с помощью jQuery