Reputation: 1511
So I have a line of code in which I want to replace all specific codes with a an image. I have it working fine with strings but when I try to enter a code I have issues.
$('#wrapper').html($('#wrapper').html().replace(/(0)/g, '<img src="/Content/Images/mana/0.png" />'));
If the (0) was a word, it would work fine, but it's replacing every single 0 in the document. Is there a way to force it to recognise the brackets as part of the string? I tried enclosing them in quotation marks but I have the same problems.
Thanks in advance
Upvotes: 1
Views: 221
Reputation: 5721
You need to escape the brackets.
$('#wrapper').html($('#wrapper').html().replace(/\(0\)/g, '<img src="/Content/Images/mana/0.png" />'));
Upvotes: 3