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.
hrefattribute value. From the docs: The href attribute on a and area elements must have a value that is a valid URLhreffor the perfectly valid reason that @RGraham mentioned above. What are you trying to do? Maybe there is a totally different solution...<%= track(1) %>intended to be JSP?