jQuery can parse it and create the elements without adding them to the DOM, then you can use Jack's suggestion:
var arr = []; $(yourHTMLstring).find('li').each(function(){ arr.push( $(this).text() ); }); - ricardo On Apr 6, 2:48 pm, Nic Hubbard <nnhubb...@gmail.com> wrote: > Yeah, I had thought of the hidden div idea, and placing the html into > that, then using .each(). I just wondered if there was a method to do > it without adding the content to the DOM. > > On Apr 6, 10:35 am, Jack Killpatrick <j...@ihwy.com> wrote: > > > d'oh, I just realized you have the html in a var... > > > I s'pose a "cheat" would be to add them to a hidden UL and then do > > something like the below so you could take advantage of the .text() and > > .each() method. Other than that, I'm not sure of the regex offhand to > > split the LI's and parse out the inner text, sry. > > > - Jack > > > Jack Killpatrick wrote: > > > maybe something like this: > > > > var ar = []; > > > $('#yourList li').each(function(){ > > > ar.push( $(this).text() ); > > > }); > > > > - Jack > > > > Nic Hubbard wrote: > > >> A better explanation: > > > >> I have a var that contains some html. Within that there are <li> > > >> elements that I need to strip the text out of and put that into an > > >> array. How would I do this? > > > >> I figure I could use each() and push(), but I am not sure how to do > > >> this grabbing it from a var. > > > >> On Apr 5, 11:30 pm, Nic Hubbard <nnhubb...@gmail.com> wrote: > > > >>> What would be the correct method to create an array from the text > > >>> inside <li> items? > > > >>> Is below, the best method, or would it even work? > > > >>> var array_test = $(#test li).text().makeArray();