Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Created February 26, 2010 23:06
Show Gist options
  • Select an option

  • Save dieseltravis/316293 to your computer and use it in GitHub Desktop.

Select an option

Save dieseltravis/316293 to your computer and use it in GitHub Desktop.
function EntityToNumeric(entity) {
var obj = document.createElement("div");
obj.innerHTML = entity;
return "&#" + (obj.textContent || obj.firstChild.nodeValue).charCodeAt(0) + ";";
}
// usage:
var html = "& ©®<>";
html = html.replace(/&\w+;/gi, EntityToNumeric);
alert(html); // "& ©®<>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment