Possible Duplicate:
How to Get Element By Class in JavaScript?
I need to get the text from inside of a span. The span has no ID. It only has a class. There would only be one span with this class. Does anyone know how I can get this span element in javascript? Thanks!
<span class="galleria-current">1</span>
This is slightly different than How to Get Element By Class in JavaScript? which is asking the more generic “get an element with a class”, in case there’s an easier way for spans, plus that question is about replacing text, whereas I want to get the innerHTML in this case.
Yes, you can use
document.getElementsByClassName().This will return an Array of all the elements with that classname. So the first one could be accessed like this:
var span = document.getElementsByClassName("galleria-current")[0]