[ACCEPTED]-reading all spans of a div dynamically-html
Accepted answer
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/
var container=document.getElementById('xyx');
var spanArray=container.getElementsByTagName('span');
for(var s=0;s<spanArray.length;s++){
spanText=spanArray[s].innerHTML;
}
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.