A couple thoughts: 'alt' isn't a valid attribute of span; use 'title'.
Using jQuery doesn't necessarily equate to easier. //POJS for (var i = 0; i < elem.length; i++) { if(!elem[i].title){elem[i].title="";} } //jQuery $('span').each(function(){ if(!this.title){this.title="";} }); On Apr 29, 3:17 pm, Andy <adharb...@gmail.com> wrote: > Is there a way to grab the text from inside a alt tag? I have a site > that will have tons of span tags and I need to go through all of them > searching for the alt="" attribute then grab it. > > I'm using some non-jQuery javascript, so I'm sure there is an easier > way to format this than what I currently have. Any thoughts on this > would be great. > > ----- html example: > > <span>text here</span> > <span alt="Joe">text here</span> > <span alt="Jim">text here</span> > <span>text here</span> > > ----- Javascript. > > // grab all spans on page. > var elem = window.opener.document.getElementsByTagName("span"); > > // make sure spans have alt attribute > for (var i = 0; i < elem.length; i++) { > if (!!$(elem[i]).attr("printElement")) { > > ???? Where do I go from here? > ..... would like to do a document.write(span element > alt value); > > } > > } > > Any thoughts on this would be great.