Reputation: 44842
I've got a HTML object obj
and I'm attempting to replace a string in it's inner HTML with another..
obj.innerHTML.replace('<a>theoldstring</a><span></span>','thenewstring');
However, the string isn't replacing and is printing the same before and after.. why?
Upvotes: 1
Views: 245
Reputation: 3668
Your call is just returning the new string. Look in the docs how javascript's replace function works.
obj.innerHTML = obj.innerHTML.replace('<a>theoldstring</a><span></span>','thenewstring');
Upvotes: 3
Reputation: 9668
obj.innerHTML = obj.innerHTML.replace('<a>theoldstring</a><span></span>','thenewstring');
Upvotes: 1
Reputation: 18041
String.replace()
does not modify the original object. Instead it returns a new instance, hence an assigment is needed:
obj.innerHTML = obj.innerHTML.replace('<a>theoldstring</a><span></span>','thenewstring');
Upvotes: 1