[ACCEPTED]-reading all spans of a div dynamically-html

Accepted answer
Score: 15

You can get the elements using document.getElementById and document.getElementsByTagName, then 4 iterate through them and add them to the 3 object. Use textContent and innerText to obtain the text of the span element, and 2 insert them into the object like so:

var spans = document.getElementById('xyx').getElementsByTagName('span'), 
    obj = {};

for(var i = 0, l = spans.length; i < l; i++){
    obj[spans[i].id] = spans[i].textContent || spans[i].innerText;

See 1 it working here: http://www.jsfiddle.net/SJs4h/

Score: 3
var container=document.getElementById('xyx');
var spanArray=container.getElementsByTagName('span');
for(var s=0;s<spanArray.length;s++){


More Related questions