You need to use a classname? Ids should be unique.
var element = document.getElementById('myId');
Or say element
is a parent and you want a child with a class
var elements = element.getElementsByTagName('*');
var newElements = [];
for (var i = 0, length = elements.length; i < length; i++) {
if ((' ' + elements[i].className + ' ').indexOf(' yourClassName ') > -1) {
newElements.push(elements[i]);
}
}
This code basically walks through all children, and uses indexOf()
to test for the presence of your class. If it finds it, it pushes it onto the new array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…