shadowayex Posted January 26, 2011 Share Posted January 26, 2011 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 More sharing options...
jeffman Posted January 26, 2011 Share Posted January 26, 2011 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 More sharing options...
ShadowMage Posted January 26, 2011 Share Posted January 26, 2011 ...and for jQuery there is the each() function. Link to comment Share on other sites More sharing options...
shadowayex Posted January 27, 2011 Author Share Posted January 27, 2011 Thank both of you for your input. Both solutions seem to work fine. Now I just have to figure out if I want to use the JQuery objects or the DOM objects Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.