[JavaScript][jQuery]HTMLをエスケープする
"<"や">"をエスケープする時、jQueryを使うと1行で書ける。
$('<div />').text(string).html();
ユーティリティ関数化しておくと便利。
/**
* HTML出力のエスケープ
*/
function escapeHTML(string) {
return $('<div />').text(string).html();
}
"<"や">"をエスケープする時、jQueryを使うと1行で書ける。
$('<div />').text(string).html();
ユーティリティ関数化しておくと便利。
/**
* HTML出力のエスケープ
*/
function escapeHTML(string) {
return $('<div />').text(string).html();
}