Skip to content Skip to sidebar Skip to footer

Js Get Value Of Generated Textnode

I have this Javascript in a for loop: renderAElements[i] = document.createElement ('a'); renderAElements[i].setAttribute('href', '#'); renderAElements[i].setAttribu

Solution 1:

Because you are trying to get the nodeValue of the Element node and not the Text node.

alert (renderAElements[i].firstChild.nodeValue);

Solution 2:

It's because the a element contains another element and not a value. If you want to get the text out of the node you'll need to do either

renderAElements.childNodes[0].nodeValue

or

renderAElements.innerText

Solution 3:

Check this out

<head><scripttype="text/javascript">functionGetTextNode () {
            var textContainer = document.getElementById ("textContainer");
            var textNode = textContainer.firstChild;
            alert (textNode.data);
        }
    </script></head><body><divid="textContainer">This is a simple text in the container.</div><buttononclick="GetTextNode ()">Get the contents of the container</button></body>

Solution 4:

try this alert (renderAElements[i].firstChild.nodeValue);

Post a Comment for "Js Get Value Of Generated Textnode"