I need to replace a html string with a dynamic value.This dynamic value(HTML encode) is to replace a pattern in the html string.
var htmlstring = "<div>{NAME}</div>";
var name = "$<Anonymous>" //Encoded form of "$<Anonymous>";
html = htmlstring.replace(/{NAME}/g,name);
I need to get "$<Anonymous>" as output but i get "{NAME}lt;Anonymous>" as output.This is because "$&" matches the whole match "{NAME}" and replace "$&" with "{NAME}".
Can anyone suggest how can I achieve this in JavaScript?