How to get child element by class name? Use doc.childNodes to iterate through each span, and then filter the one whose className equals 4: