i have this js code :
var str = "javascript:__doPostBack('ctl00$M$List$_rli2$ctl06','')";
alert (str);
var str = str.replace(/\$_rli\d+/, "$_rli" + 7);
alert (str);
And in IE it produces me result as follows:
javascript:__doPostBack('ctl00$M$Listjavascript:__doPostBack('ctl00$M$List$_rli2$ctl06','')rli7$ctl06','')
while it should work like this:
javascript:__doPostBack('ctl00$M$List$_rli7$ctl06','')
and it does in FF, Opera and Chrome.
It Replaces $_ with whole previous string. No escape sequences seems to help.
What am i Doing wrong?
This is due to the way Internet Explorer handles references in replace. Use
$$instead, which should work in all browsers:Alternatively, if you wanted to make it a bit clearer you could use an anonymous function that returns the replacement string: