I am pretty new to Javascript and I need to get the value of the node with id firstvalue so that I can use it in my script. Can anyone please tell me how do I get that value?
<div id="myDiv">
<span id="firstValue"> 5.22 <span id="nestedValue"> 500 </span></span>
</div> <!-- myDiv -->
document.getElementById("firstValue")will get you a reference to the<span>. This has two child nodes, which you can reference via the array-likechildNodesproperty, or in this case simply usingfirstChildandlastChildproperties. For example, the following will return you the string ” 5.22 “: