Reputation: 544
I am attempting to replace the word 'and' with 'dog', using JavaScript. Here is my code:
var magic = document.getElementById("magic");
function myFunction() {
magic.innerHTML.replace('and', 'dog');
}
myFunction;
Upvotes: 0
Views: 2356
Reputation: 2607
var magic = document.getElementById("magic");
function myFunction() {
magic.innerHTML = magic.innerHTML.replace('and', 'dog');
}
myFunction();
Upvotes: 2
Reputation: 96250
replace
does not change the input, it returns the changed value – so you have to assign it to magic.innerHTML
again.
Upvotes: 4