function getElementsClass(classnames){ var classobj= new Array(); var classint=0; var tags=document.getElementsByTagName("span"); for(var i in tags){ if(tags[i].nodeType==1){ if(tags[i].getAttribute("class") == classnames) { classobj[classint]=tags[i]; classint++; } } } return classobj; } var a = getElementsClass("icons1"); //document.getElementById("navigation").innerHTML = "Views:12"; a[0].innerHTML = "Views:12";