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:
<head>
<script type="text/javascript">
function GetTextNode () {
var textContainer = document.getElementById ("textContainer");
var textNode = textContainer.firstChild;
alert (textNode.data);
}
</script>
</head>
<body>
<div id="textContainer">This is a simple text in the container.</div>
<button onclick="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"