JS tiny text replace problem
Under normal circumstances I would simply look this up, but I don't have my JS reference so...
I have this code:
var text = document.createTextNode(alt);
var empty = document.createTextNode("");
desc.appendChild开发者_StackOverflow(empty);
desc.appendChild(text);
I need to alter the appendChild to something that will replace the current child value rather than add to it. I've googled for this and come up short for some reason.
Try this:
desc.replaceChild(text, desc.firstChild);
desc.innerHTML = 'some text';
- simplest way i think
Um, how about replaceChild?
desc.replaceChild(text,empty);
This replaces the empty child node with the text child node.
精彩评论