html代码:
<div class="div1">111</div> <div class="div1">222</div> <div class="div1">333</div>
javascript代码:
function getClassName(clsName,parent){ var oParent=document.getElementById(parent)||document; var elements=oParent.getElementsByTagName("*"); var ele=[]; for(var i=0;i<elements.length;i++){ if(elements[i].className==clsName){ ele.push(elements[i]); } } return ele; } console.log(getClassName("div1")[1].innerHTML);