jQuery: The Write Less, Do More JavaScript Library

$.fn.add(selector) and context

View: New views
6 Messages — Rating Filter:   Alert me  

$.fn.add(selector) and context

by Robert Katić :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Using $.fn.add(selector) the context property remains the same.
It's ok, but the given selector will be applied always with the
default context (document).

This is not correct for me if we are using jQuery with xml documents
for example.

  $("user", xmlDoc).add("lusers");

There is no way to add lusers of the xmlDoc document!

Here an optional context argument would be useful:

  $("user", xmlDoc).add("lusers", xmlDoc);

But even this is not ideal for me. If the context argument is not
given (first example), which document would be used?
I suppose the obvious answer is xmlDoc.

An corrected implementation of add() would be something like this:

jQuery.fn.add = function( selector ) {
    return this.pushStack( jQuery.unique( jQuery.merge(
        this.get(),
        typeof selector === "string" ?
            jQuery( selector, (this.context || this[0] ||
0).ownerDocument ) :
            jQuery.makeArray( selector )
    )));
};

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: $.fn.add(selector) and context

by Robert Katić :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, I posted an old version of code. Here the new one:

jQuery.fn.add = function( selector, context ) {
    return this.pushStack( jQuery.unique( jQuery.merge(
        this.get(),
        typeof selector === "string" ?
            jQuery( selector, context
                || this.context && (this.context.ownerDocument ||
this.context)
                || this[0] && (this[0].ownerDocument || this[0]) ) :
            jQuery.makeArray( selector )
    )));
};

On Oct 30, 6:55 am, Robert Katić <robert.ka...@...> wrote:

> Using $.fn.add(selector) the context property remains the same.
> It's ok, but the given selector will be applied always with the
> default context (document).
>
> This is not correct for me if we are using jQuery with xml documents
> for example.
>
>   $("user", xmlDoc).add("lusers");
>
> There is no way to add lusers of the xmlDoc document!
>
> Here an optional context argument would be useful:
>
>   $("user", xmlDoc).add("lusers", xmlDoc);
>
> But even this is not ideal for me. If the context argument is not
> given (first example), which document would be used?
> I suppose the obvious answer is xmlDoc.
>
> An corrected implementation of add() would be something like this:
>
> jQuery.fn.add = function( selector ) {
>     return this.pushStack( jQuery.unique( jQuery.merge(
>         this.get(),
>         typeof selector === "string" ?
>             jQuery( selector, (this.context || this[0] ||
> 0).ownerDocument ) :
>             jQuery.makeArray( selector )
>     )));
>
> };

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: Re: $.fn.add(selector) and context

by John Resig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This seems reasonable, as well. Can you file a ticket? Thanks.

--John



On Fri, Oct 30, 2009 at 2:06 AM, Robert Katić <robert.katic@...> wrote:

> Sorry, I posted an old version of code. Here the new one:
>
> jQuery.fn.add = function( selector, context ) {
>    return this.pushStack( jQuery.unique( jQuery.merge(
>        this.get(),
>        typeof selector === "string" ?
>            jQuery( selector, context
>                || this.context && (this.context.ownerDocument ||
> this.context)
>                || this[0] && (this[0].ownerDocument || this[0]) ) :
>            jQuery.makeArray( selector )
>    )));
> };
>
> On Oct 30, 6:55 am, Robert Katić <robert.ka...@...> wrote:
>> Using $.fn.add(selector) the context property remains the same.
>> It's ok, but the given selector will be applied always with the
>> default context (document).
>>
>> This is not correct for me if we are using jQuery with xml documents
>> for example.
>>
>>   $("user", xmlDoc).add("lusers");
>>
>> There is no way to add lusers of the xmlDoc document!
>>
>> Here an optional context argument would be useful:
>>
>>   $("user", xmlDoc).add("lusers", xmlDoc);
>>
>> But even this is not ideal for me. If the context argument is not
>> given (first example), which document would be used?
>> I suppose the obvious answer is xmlDoc.
>>
>> An corrected implementation of add() would be something like this:
>>
>> jQuery.fn.add = function( selector ) {
>>     return this.pushStack( jQuery.unique( jQuery.merge(
>>         this.get(),
>>         typeof selector === "string" ?
>>             jQuery( selector, (this.context || this[0] ||
>> 0).ownerDocument ) :
>>             jQuery.makeArray( selector )
>>     )));
>>
>> };
>
> --
>
> You received this message because you are subscribed to the Google Groups "jQuery Development" group.
> To post to this group, send email to jquery-dev@....
> To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
> For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: Re: $.fn.add(selector) and context

by Scott Sauyet-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>       || this.context && (this.context.ownerDocument || this.context)

There's something -- let's say redundant -- about this line.  :-)

  -- Scott

(a && (b || a)) == a

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: Re: $.fn.add(selector) and context

by Scott Sauyet-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 30, 2009 at 10:34 AM, Scott Sauyet <scott.sauyet@...> wrote:
> There's something -- let's say redundant -- about this line.  :-)

Ignore me.  Brain fart.

  -- Scott

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: $.fn.add(selector) and context

by Robert Katić :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ticket: http://dev.jquery.com/ticket/5434

On Oct 30, 3:33 pm, John Resig <jere...@...> wrote:

> This seems reasonable, as well. Can you file a ticket? Thanks.
>
> --John
>
> On Fri, Oct 30, 2009 at 2:06 AM, Robert Katić <robert.ka...@...> wrote:
> > Sorry, I posted an old version of code. Here the new one:
>
> > jQuery.fn.add = function( selector, context ) {
> >    return this.pushStack( jQuery.unique( jQuery.merge(
> >        this.get(),
> >        typeof selector === "string" ?
> >            jQuery( selector, context
> >                || this.context && (this.context.ownerDocument ||
> > this.context)
> >                || this[0] && (this[0].ownerDocument || this[0]) ) :
> >            jQuery.makeArray( selector )
> >    )));
> > };
>
> > On Oct 30, 6:55 am, Robert Katić <robert.ka...@...> wrote:
> >> Using $.fn.add(selector) the context property remains the same.
> >> It's ok, but the given selector will be applied always with the
> >> default context (document).
>
> >> This is not correct for me if we are using jQuery with xml documents
> >> for example.
>
> >>   $("user", xmlDoc).add("lusers");
>
> >> There is no way to add lusers of the xmlDoc document!
>
> >> Here an optional context argument would be useful:
>
> >>   $("user", xmlDoc).add("lusers", xmlDoc);
>
> >> But even this is not ideal for me. If the context argument is not
> >> given (first example), which document would be used?
> >> I suppose the obvious answer is xmlDoc.
>
> >> An corrected implementation of add() would be something like this:
>
> >> jQuery.fn.add = function( selector ) {
> >>     return this.pushStack( jQuery.unique( jQuery.merge(
> >>         this.get(),
> >>         typeof selector === "string" ?
> >>             jQuery( selector, (this.context || this[0] ||
> >> 0).ownerDocument ) :
> >>             jQuery.makeArray( selector )
> >>     )));
>
> >> };
>
> > --
>
> > You received this message because you are subscribed to the Google Groups "jQuery Development" group.
> > To post to this group, send email to jquery-dev@....
> > To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
> > For more options, visit this group athttp://groups.google.com/group/jquery-dev?hl=en.

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.