Hi Mike, You're right, I want to be able to use this.rowTextArray later on.
You're code suggestion works great! Thanks so much for the help!! Regards, Marty On Oct 6, 1:24 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > That's right, the mistaken use of "this" is the problem - one of them anyway > - but that solution won't work (what is the "parent" property of a DOM > element?). > > Another problem is the misuse of "push" - it's a method, not a property you > can store into. (You *can* store into the "push" property - as the code does > successfully, but what that does is replace the normal "push" method with > your data!) > > Marty, I assume that the purpose of the second example is so you'll have > this.rowTextArray available for use elsewhere in your code, is that right? > > Then try this (pun intended): > > // build an array of text on the line > var rowTextArray = this.rowTextArray = []; > > // add text into array > this.$children.each( function() { > rowTextArray.push( encodeURIComponent( $(this).text() ) ); > }); > > Note the correct use of .push, and also the optional (but nicer) use of [] > instead of new Array(). > > I also took the liberty of renaming the "children" property "$children", a > naming convention I highly recommend (and you'll see in much jQuery code) > when you have a variable or property containing a jQuery object as I assume > this.children does. > > -Mike > > > From: MorningZ > > > i would take a guess that you are missing that "this" points > > to two different things inside and outside the ".each" loop > > > which makes sense because you have "this" on the outside, and > > then loop against "this.children", so inside the loop "this" > > actually is the "nth child of this" > > > see if > > > this.children.each( function() { > > this.parent.rowTextArray.push = encodeURIComponent( $ > > (this).text() ); > > } ); > > > works... although i will note that is just a shot in the dark > > without seeing more of your script > > > On Oct 6, 1:22 pm, marty <[EMAIL PROTECTED]> wrote: > > > This is driving me crazy > > > > I'm trying to copy elements from a wrapped set into an array. > > > > This works: > > > > // build an array of text on the line > > > var rowTextArray = new Array(); > > > > // add text into array > > > this.children.each( function() { > > > rowTextArray.push = encodeURIComponent( > > > $(this).text() ); > > > } ); > > > > This does not: > > > > // build an array of text on the line > > > this.rowTextArray = new Array(); > > > > // add text into array > > > this.children.each( function() { > > > this.rowTextArray.push = > > encodeURIComponent( > > > $(this).text() ); > > > } ); > > > > Here's the error I get: > > > Error: this.rowTextArray is undefined > > > > Any help would be greatly appreciated!! > > > > Regards, > > > Marty