I have a query in which i want to set the value of second span in the div.
<div id="content">
<h1>Welcome</h1>
<span>This is the first span</span>
<span>This is the second span</span>
<span>This is the 3rd span</span>
</div>
I am using following javascript.
function SetValue(myValue) {
var mainDiv = document.getElementById("content");
for(var i=0;i<mainDiv.childNodes.length;i++) {
if(mainDiv.childNodes[i] == 2) {
mainDiv.childNodes[i].innerText = myValue;
}
}
}
i want to get the parameter value to be set in second span of the main div
How about this pure JS implementation, since there is no indication, besides the tag, that JQuery is an option and it is totally not needed for something like this:
http://jsfiddle.net/MTSAN/1/