I have the following problem:
var bodyHtml = 'Test7\n'
+ '<a href="www.google.com">Google</a>\n'
+ '<a href="www.google.com">Google</a>\n'
+ '<a href="www.yahoo.com">Yahoo</a>';
var $tempHtml = $("<tempHtml/>").html(bodyHtml);
$tempHtml.find("a").each(function (index, a) {
var url = $(a).attr("href");
if (url === "www.google.com") {
$(a).attr("href", "<%= track(1) %>");
}
});
bodyHtml = $tempHtml.html();
Here is a JSBin for this. The problem that I have with this is that the JQuery .html()
function replaces <%
inside href
tags with <%
(escapes it). Is there any way of preventing this escaping since I need the string bodyHtml
to remain unchanged?
I know how this could be done over RegEx
, but this JQuery
solution seems better if it could be done.