🔰 JS ⟩ Types ⟩ String ⟩ methods
👉 see: encodeURI() ⭐️
💾 程式:codepen ⟩ escapeHTML() ⭐️
// ⭐️ escapeHTML() export function escapeHTML(str){ return new Option(str).innerHTML; } // ⭐️ str.escapeHTML() String.prototype.escapeHTML = function(){ return escapeHTML(this); } // ⭐️ escape HTML special characters (deprecated❗️) String.prototype.escapeHTML = function () { return this .replace(/&/g, '&' ) // ampersand (must be first❗️) .replace(/>/g, '>' ) // greater than .replace(/</g, '<' ) // less than .replace(/"/g, '"') // double-quote .replace(/'/g, ''' ) // single-quote .replace(/`/g, '`' ); // backtick }
str.replace()
str.kebabToCamelCase()
Events that Cross Shadow DOM Boundary
⭐️ Fav
encodeURI() ⭐️
NEWBEDEV ⟩ How to escape HTML
GitHub Gist ⟩ escaping with the DOM
Document ⟩ .createTextNode() - creates a new Text node. This method can be used to escape HTML characters.
Text
Last updated 2 years ago