[jQuery] Re: not defined error using instance variable in each callback
Thanks very much for the reply! That was a big help! I was missing the fact that this inside the loop is not the same as this outside the loop. Your suggestion really helped! Regards, Marty On Oct 6, 12:59 pm, MorningZ [EMAIL PROTECTED] wrote: 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
[jQuery] Re: not defined error using instance variable in each callback
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
[jQuery] Re: not defined error using instance variable in each callback
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
[jQuery] Re: not defined error using instance variable in each callback
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
[jQuery] Re: $ Not defined
I am having trouble with the $ not defined error and after reading Karl's response (http://groups.google.com/group/jquery-en/ browse_thread/thread/17dab2899c5cfc18/7312dc68c84d93af?lnk=gstq=%24+is +not+defined#7312dc68c84d93af) I have assured myself that it is in fact NOT loading my local copy of the jquery file. I have tried placing it in the same directory as the calling file, my js directory, all diff places. I renamed the download file to jquery126.js and did the following... script type=text/javascript src=js/jquery126.js/script script type=text/javascript src=js/global.js/script Oddly enough when using firebug - I can confirm that the jquery file is giving me a 404 - yet the global.js file is being served just fine. They are both located in the same placve, I have confirmed the file spelling etc. I even tried using the Dreamweaver code hints to help me browse for and select the correct file. Yet the only file that will not wok is my jquery file. Any ideas anyone? What type of webserver are you using? Sometimes webapps need to be bounced when deployed into app servers like WebSphere in order to redeploy static resources. Mike
[jQuery] Re: $ Not defined
I had a similar problem recently, and it turned out to be a permissions issue with just the jquery source file. Fixed the permissions problem, and the file started getting included properly. Have you looked at a possible permissions issue? Chris On Thu, Aug 28, 2008 at 11:04 AM, Chris [EMAIL PROTECTED] wrote: I am having trouble with the $ not defined error and after reading Karl's response (http://groups.google.com/group/jquery-en/ browse_thread/thread/17dab2899c5cfc18/7312dc68c84d93af?lnk=gstq=%24+is +not+defined#7312dc68c84d93afhttp://groups.google.com/group/jquery-en/browse_thread/thread/17dab2899c5cfc18/7312dc68c84d93af?lnk=gstq=%24+is+not+defined#7312dc68c84d93af) I have assured myself that it is in fact NOT loading my local copy of the jquery file. I have tried placing it in the same directory as the calling file, my js directory, all diff places. I renamed the download file to jquery126.js and did the following... script type=text/javascript src=js/jquery126.js/script script type=text/javascript src=js/global.js/script Oddly enough when using firebug - I can confirm that the jquery file is giving me a 404 - yet the global.js file is being served just fine. They are both located in the same placve, I have confirmed the file spelling etc. I even tried using the Dreamweaver code hints to help me browse for and select the correct file. Yet the only file that will not wok is my jquery file. Any ideas anyone? Thanks, Chris -- http://cjordan.us
[jQuery] Re: Element defined or not
Try if ($(selector).length0){ //... } On 7/10/07, Sebastián V. Würtz [EMAIL PROTECTED] wrote: Wich is the best way to know if a element for example a div is defined? like in php if ( empty($test) ) or if ( isset($test) ) thx
[jQuery] Re: Element defined or not
On 7/10/07, Sebastián V. Würtz [EMAIL PROTECTED] wrote: Wich is the best way to know if a element for example a div is defined? We get this question a lot. jQuery returns the DOM in an array like fashion. This is standard: if($(div).length) ... or sometimes: var div = $(div)[0]; if(div) ... ~Sean