Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating through all the <div> tags on a page

I want to go through all the elements on a page using Javascript and see if they have a property set. Is there an easy way to do this, or do I have to use a recursive solution?

like image 574
Sam Lee Avatar asked May 10 '09 07:05

Sam Lee


1 Answers

You can use:

var divs = document.getElementsByTagName("div"); for(var i = 0; i < divs.length; i++){    //do something to each div like    divs[i].innerHTML = "something new..."; } 
like image 146
Jose Basilio Avatar answered Oct 16 '22 07:10

Jose Basilio