> $(document).ready(function(){
> $("form .control.date").each( function(i){
> var me = $(this)
> alert( me.find( '[EMAIL PROTECTED]"text"]').val() );
> alert( me.find( '[EMAIL PROTECTED]"hidden"]').val() );
> alert( me.find( 'input.meta').val() );
>
> } );
> });
> Now using the FULL jquery library, I get "HI" followed by NULL twice.
You are not alone, there was a similar post a few days ago:
http://www.nabble.com/parent%28%29-modifies-original-object-tf2461335.html
I think the confusion comes from storing a jQuery object in a variable with
a name that implies it represents an unchangeable set of DOM nodes. That's
not the way a jQuery object works. The methods you apply to it can change
its internal state, if that's what you want to do. This plain Javascript
does the same:
var heavyCream = ["it", "whip", "good"];
alert(heavyCream.sort()); // good, it, whip
alert(heavyCream.reverse()); // whip, it, good
alert(heavyCream.pop()); // good
alert(heavyCream); // whip, it
Applying methods to a plain Javascript array changed its internal state,
just like the jQuery example. The name of the variable still implies it's
talking about heavy cream, but by the end the value sounds like Devo lyrics.
I totally agree that this can be unexpected behavior and that it needs to be
documented better in the "getting started" writeups. By using chained
methods you can avoid assigning jQuery objects to variables, and don't fall
into the trap of naming the variable as if it will always refer to the same
nodes.
Making it so that "destructive" methods return a fresh object would be a big
deal. I know I have code that depends on pushStack so it's definitely a
breaking change. There are also performance and memory issues to think
about. Still, if a lot of people are finding this a barrier to understanding
jQuery we need to find some solution.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/