Here is the working [demo][1]demo . but really didn't understood what you expected. Please, Find the explanation of the code below.
var amy= document.getElementsByTagName('div');
Above line just selects the Div tags on HTML page. Now current HTML contains three DIV tags wrapped in main DIV, i.e. total 4 DIV elements. So, First alert is '4'.
for (var i=0;i<amy.length-1;i++){
var jar= amy[i];
alert(jar.innerHTML);
}
This code loops through four DIV tags. innerHTML is used to display the content inside that div. You will See, First The whole DIV block alerted. After this, Every div will be alerted.
Please, Let me know this is what you wanted ? [1]: http://jsfiddle.net/umeshpatil86/89w5d/
Here is the working [demo][1] . but really didn't understood what you expected. Please, Find the explanation of the code below.
var amy= document.getElementsByTagName('div');
Above line just selects the Div tags on HTML page. Now current HTML contains three DIV tags wrapped in main DIV, i.e. total 4 DIV elements. So, First alert is '4'.
for (var i=0;i<amy.length-1;i++){
var jar= amy[i];
alert(jar.innerHTML);
}
This code loops through four DIV tags. innerHTML is used to display the content inside that div. You will See, First The whole DIV block alerted. After this, Every div will be alerted.
Please, Let me know this is what you wanted ? [1]: http://jsfiddle.net/umeshpatil86/89w5d/
Here is the working demo . but really didn't understood what you expected. Please, Find the explanation of the code below.
var amy= document.getElementsByTagName('div');
Above line just selects the Div tags on HTML page. Now current HTML contains three DIV tags wrapped in main DIV, i.e. total 4 DIV elements. So, First alert is '4'.
for (var i=0;i<amy.length-1;i++){
var jar= amy[i];
alert(jar.innerHTML);
}
This code loops through four DIV tags. innerHTML is used to display the content inside that div. You will See, First The whole DIV block alerted. After this, Every div will be alerted.
Please, Let me know this is what you wanted ?
Here is the working [demo][1] . but really didn't understood what you expected. Please, Find the explanation of the code below.
var amy= document.getElementsByTagName('div');
Above line just selects the Div tags on HTML page. Now current HTML contains three DIV tags wrapped in main DIV, i.e. total 4 DIV elements. So, First alert is '4'.
for (var i=0;i<amy.length-1;i++){
var jar= amy[i];
alert(jar.innerHTML);
}
This code loops through four DIV tags. innerHTML is used to display the content inside that div. You will See, First The whole DIV block alerted. After this, Every div will be alerted.
Please, Let me know this is what you wanted ? [1]: http://jsfiddle.net/umeshpatil86/89w5d/