Tuesday, 15 April 2014

jquery - Replace all instances particular tag when HTML may be malformed -



jquery - Replace all instances particular tag when HTML may be malformed -

we're trying write script replaces deprecated tags, such <font>, content. have along lines of:

while($("font").length > 0) { $("font").each(function() { $(this).replacewith($(this).html()); }); }

the while loop because if font tag replaced it's content , 1 of elements children font tag catches both parent , child.

our problem have no command on content beingness output - entered our clients. 1 illustration of malformed html we've seen <p><font><span><font><div></font><strong></strong><strong></div></span></font></p>. majorly malformed , in ideal world our clients come in correctly. above script works on in decent browsers - chrome, firefox & safari - , surprisingly ie 9. breaks in ie 6-8, resulting in none of content within these tags beingness displayed. we're aiming font tags replaced , content within them still displayed.

does know of way can accomplish desired effect either jquery or classic asp?

also note in particular clients case pretty basic - 1 tag has been requested replaced. other cases include tags added word when transfer text word website, <i>, <b>, <span> , on.

thanks in advance, regards, richard

wouldn't easier replace <font> , </font> tags output? in given case still not deliver validating xhtml code (<div> within of <span>, unclosed <strong>), maybe suffice view text.

here how in classic asp using regexp:

function removefonttags(s_text) dim obj_regex set obj_regex = new regexp obj_regex.ignorecase = true obj_regex.global = true obj_regex.pattern = "\<\/?font\>" removefonttags = obj_regex.replace(s_text, "") set obj_regex = nil end function response.write removefonttags("<p><font><span><font><div></font><strong></strong><strong></div></span></font></p>") ' returns: <p><span><div><strong></strong><strong></div></span></p>

but maybe add together farther sanitation way display need.

jquery asp-classic

No comments:

Post a Comment