0

I am needing to, on form submit, look at a certain textarea being submitted and check for all <code> tags. Then take everything between a <code> tag set and run this function on this function on it:

function escapeHtml(unsafe) {
return unsafe
    .replace(/&/g, "&amp;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&#039;");
}

I was thinking of using :

$("code").each(function (){ });

Will that work? I'm testing it now but would like to know if there is a better way.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
Cow
  • 764
  • 5
  • 10
  • 25

1 Answers1

0

Look at same questions Fastest method to escape HTML tags as HTML entities? OR Escape HTML using jQuery. You can choose answer from one of them.

Community
  • 1
  • 1
webdeveloper
  • 17,174
  • 3
  • 48
  • 47