Languages

Menu
Sites
Language
How to get the all class name with in div tag?
How  to get the all class name with in tag, I want get class name one and two, Any one please help me
 
    <div id="svgcanvas" style="position:relative">
        <div class="one"></div>
        <div class="two"></div>
     </div> 

Responses

1 Replies
Marco Buettner
var classes = [],
    parent = document.querySelector('#svgcanvas'),
    child = null,
    i = 0;

if(parent.hasChildNodes) {
    for(i; i < parent.childNodes.length; i++) {
        child = parent.childNodes[i];
        classes.push(child.className);
    }

    alert(JSON.stringify(classes));
}