Reputation: 55
Here's what I have:
I create this markup on the fly:
<p id="amount"><span></span></p>
Now I need to fill up the span:
if (amount.firstChild.nodeType == 1) {
amount.firstChild.nodeValue = text;
alert(description.firstChild.nodeType); //this shows SPAN
}
amount is a variable created with getElementbyId and text is a variable that it works and shows just a figure.
Now, why isn't accepting text as a value? It renders and empty span... and text is working just fine....
thanks a lot fellas!
Upvotes: 0
Views: 183
Reputation: 3694
You can test for a nested text node in the span, and if there isn't one, create it.
var span = amount.firstChild
if (!span.firstChild)
span.appendChild(document.createTextNode(text));
else
span.firstChild.nodeValue = text;
Upvotes: 0
Reputation: 253308
Try using:
amount.firstChild.appendChild(document.createTextNode(text));
Upvotes: 2