Jump to content

Getting text from multiple elements


shadowayex

Recommended Posts

For this particular example, I'll use JQuery, but I am open to pure JavaScript solutions as well.I'm getting a group of span tags via something of the sort parent.children("span") and I want to get each one's text contents in either a separate, or a separable form (maybe with a delimiter or something). Just using .text() seems to get me a string that is smashed together and not parsable. Is there such a way with either JQuery or JavaScript to do this easily?P.S.: I know I could use a loop, but my code is already using a couple loops, and I wanted to see if there was a faster away. If not, loops it is.

Link to comment
Share on other sites

Don't fear loops. Even if jQuery has such a tool, inside it there is a loop. We use loops all the time.Pure javascript would do this sort of thing:var mySpans = parent_element.getElementsByTagName('span');for blah blahtext = mySpans.innerHTML;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...