Hi Adam -
This is due to the fact that .find() is a destructive operation, as
you noted - it modifies the original object. We've been looking at
ways to make the operation non-destructive, but still chainable. The
problem is that jQuery has been like this since day 1, and making a
change of this magnatude would have to wait until jQuery 2.0. Unless a
plugin were developed that could allow you to have the functionality
straight away. I'll look into this more and see if I can find an
acceptable compromise.
--John
On 10/19/06, Adam van den Hoven <[EMAIL PROTECTED]> wrote:
> Hey guys,
>
> I'm just starting with jquery and I've hit what seems to be
> inconsistant behaviour. I have the following markup:
>
> <form action="">
> <span class="control date">
> <input id="someID" type="text" value="HI" />
> <input type="hidden" value="Huh?" class="meta" />
> </span>
> <br />
> </form>
>
>
> The values are only there becuase I had problems and I wanted to test stuff.
>
> I then wrote the following javascript:
>
> $(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 this made sense to me at the time, but I've learned of better ways
> to do this.
>
> Now using the FULL jquery library, I get "HI" followed by NULL twice.
> When I was using only the base and event modules (I think.. no ajax or
> animation) I got back an jQuery object.
>
> I've since learned that this is the better way to do it:
> alert($('[EMAIL PROTECTED]"hidden"]', this).val())
>
> It seems to me a flaw in jQuery that such a thing could happen. First
> getting different results for the same (more or less) operation is a
> bad thing but also having different things come back seems like a bad
> idea.
>
> Adam
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
--
John Resig
http://ejohn.org/
[EMAIL PROTECTED]
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/