How do I access multiple divs properties?

jackroger

Banned
Jul 15, 2010
10
0
0
Hey


I need to access multiple divs at once. I cannot use ids and I was wondering if there was a way in javascript to access something like htmls class?


thanks
 


use jquery.

or

Code:
function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
 
Code:
var variableName = document.getElementsByTagName['div'];
That's the javascript for it. Granted, you can do another getElementById or something to tack on before that getElementsByTagName to narrow down where it's getting the divs.

It will store them all in an array, so you'll have to sift through them in order of where they loaded on the page.

Edit:

Just saw GrassBlades bumped an old thread, nvm.