Iterating through all the <div> tags on a page Iterating through all the <div> tags on a page javascript javascript

Iterating through all the <div> tags on a page


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...";}


To find a property in one or more of all divs on a page:

var divs = document.getElementsByTagName("div"), i=divs.length;while (i--) {   if (divs[i].getAttribute([yourProperty]) === 'yourValue'){      //do something   } }


You might also be able to use a selector engine such as Sizzle.

Steve