function getFirstSpanWithClass(cssClass) {
var elements = document.getElementsByTagName('span');
for (var i = 0; i < elements.length; i++) {
if((' ' + elements[i].className + ' ').indexOf(' ' + cssClass + ' ') > -1) {
return elements[i];
}
}
}
var span = getFirstSpanWithClass('galleria-current'); // should return your span element.
if (span){
// in case there is a span on the page, write its innerHTML to console
console.log(span.innerHTML);
}
そして、それらすべてを提供する例:
function getSpansWithClass(cssClass) {
var elements = document.getElementsByTagName('span');
var out = [];
for (var i = 0; i < elements.length; i++) {
if((' ' + elements[i].className + ' ').indexOf(' ' + cssClass + ' ') > -1) {
out.push(elements[i]);
}
}
return out;
}