There are a piece of code,but can not use <id> tag.
<id>
So,how do I get to the <span> 1 2 3 4?
<span> 1 2 3 4
<div id="test"> <span>1</span> <span>2</span> <span>3</span> <span>4</span> <div>
Try this
var div = document.getElementById("test"); var spans = div.getElementsByTagName("span"); for(i=0;i<spans.length;i++) { alert(spans[i].innerHTML); }
1.4m articles
1.4m replys
5 comments
57.0k users