Keith Power Keith Power - 7 months ago 24
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

.replace
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

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!
Comments