Reputation: 10554
// create text <span>
var text = document.createTextNode("Some content I want to replace... ");
var textspan = document.createElement("span");
textspan.id = "text" + counter;
textspan.appendChild(text)
div.appendChild(textspan);
// edit <span> content
document.getElementById("text" + this.index).innerHtml = 'hello';
console.log(document.getElementById("text" + this.index).innerHtml);
console.log(document.getElementById("text" + this.index));
result
> hello
> <span id="text0">Some content I want to replace </span>
InnerHtml changes correctly but the browser (and the console) still display the wrong content. Why is that?
Upvotes: 0
Views: 1905
Reputation: 255
It would be better to use jquery $('#your_id').html('some kind of a text');
, but if js suits you then innerHTML or innerText is used, as mentioned in other answers.
Upvotes: 0
Reputation: 484
You can change the content by setting your string to innerHTML
or innerText
Element properties. It is obviously what property for which there
Upvotes: 0
Reputation: 22637
It's innerHTML
, not innerHtml
.
Remember that in Javascript everything is case sensitive.
Upvotes: 4