Escaping Contents of HTML with jQuery -


i'm running function cycle through elements on email newsletter , escape html.

function escapechars() {     iframe.contents().find('[data-mailbuilder="article-content"]')     .children()     .each(function() {         $(this).text(escapehtml($(this).text()));     }); }   function escapehtml(unsafe) {     return unsafe     .replace(/&/g, "&amp;")     .replace(/</g, "&lt;")     .replace(/>/g, "&gt;")     .replace(/"/g, "&quot;")     .replace(/'/g, "&#039;"); } 

however jquery seems replace '&' '&amp;' without escaping character.

any ideas?

to render html use .html() instead of .text(). so, change to:

$(this).html(escapehtml($(this).text())); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -