How do I get element's className inside loop of elements?

Posted by crosenblum on Stack Overflow See other posts from Stack Overflow or by crosenblum
Published on 2010-04-21T15:47:51Z Indexed on 2010/04/21 16:13 UTC
Read the original article Hit count: 268

Filed under:
|
|

I am doing a loop of all elements inside a div, and I now need to get the classname of the element that I am looping by.

Then i can check if the current element's class is one, I need to do something with...

 // var children = parent.childNodes, child;
    var parentNode = divid;

    // start loop thru child nodes
    for(var node=parentNode.firstChild;node!=null;node=node.nextSibling){

    var myclass = (node.className ? node.className.baseVal : node.getAttribute('class'));

    }

But this code for getting the classname only get's null values.

Any suggestions?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about element