I am trying to replace "this" in the below example with "$$Ashok".I am not getting expected output.
var adHtmltext ="this is ashok"
adHtmltext = adHtmltext.replace("this", "$$Ashok");
alert(adHtmltext );
why it is showing one $ in output? how to fix this?
Here is the jsfiddle http://jsfiddle.net/RxDa5/
Please help.
Have a look at the MDN documentation:
The replacement string can include the following special replacement patterns:
$$
Inserts a "$".
So you have to do:
adHtmltext.replace("this", "$$$$Ashok");
See also Javascript string replace weirdness -- $$$$ gets collapsed to $$ -- what's the reason behind this result?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With