Keith Power Keith Power - 1 year ago 92
Javascript Question

javascript .replace a html tag does not replace

I am trying to replace some html but the replace is not taking place. I am using the javascript

and from what I can see I am using it right.

content.replace('<link rel="stylesheet" href="style.css">', '<style>html{background-color: blue;}<\/style>');

Answer Source

The strings replace() method returns a new string with the new value. It doesn't modify the original string.

Here is a simple example:

var str = "Hello World!";
var res = str.replace("World", "Foo");

console.log(str);  // prints Hello World!
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download