replace() function not working in Internet Explorer

14,094

Try it with a regular expression:

.replace(/Payment by <b>Moneybookers<\/b> e-wallet<br>/, "")

If that doesn't work, try making it case insensitive. Internet Explorer might be converting the tags to upper case.

.replace(/Payment by <b>Moneybookers<\/b> e-wallet<br>/i, "")

On a different point, replacing the entire body's innerHTML probably isn't a great idea. Every DOM element in the page would be destroyed, the new HTML re-parsed and then new elements created. Perhaps try to narrow down your replacement to the element which actually contains this text.

Share:
14,094
LEOPM
Author by

LEOPM

Updated on June 21, 2022

Comments

  • LEOPM
    LEOPM almost 2 years

    I have a js replace function to replace text next to two radio buttons on a pre set form.

    Script is as follows.

    document.body.innerHTML = document.body.innerHTML.replace(
        "Payment by <b>Moneybookers</b> e-wallet<br>", ""
    );
    document.body.innerHTML = document.body.innerHTML.replace(
        "Maestro, Visa and other credit/debit cards by <b>Moneybookers</b>",
        "Pago con Diners Club, Mastercard o Visa"
    );
    

    The script works fine in Chrome and Firefox, however, the script is not actioned in Explorer.

    I believe it has something to do with there being , / - within the text I am replacing? When I use the function to replace text with no , / - in the text - it works fine in explorer, however, for example when I try to replace text.. - "Maestro, Visa and other credit/debit cards by Moneybookers" this does not work in explorer.. I'm assuming because of the coma and forward slash. Honestly I've tried everything but just can not get this to work. Any help would be greatly appreciated!!