jQuery: The Write Less, Do More JavaScript Library

$(nodeList) and comment nodes

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

$(nodeList) and comment nodes

by Robert Katić :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

jQuery.merge() is the only function that discards comment nodes (?).

This means that

  $( nodeList )

can contains comment nodes, but

  $([]).add( nodeList  )

can not.

Why such different behaviors?
Is the jQuery.makeArray() more appropriate to filter comment nodes?
Am I missing something here?

--

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: $(nodeList) and comment nodes

by Robert Katić :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

To be more accurate,

  $([]).add( nodeList  )

can not contains comment nodes only on IE.
This makes it even more ambiguous, with unexpected results.
Also it seams that the only expected NodeList is from an
getElementsByTagName.call.

I know that it is not explicitly supported by the API, but even then
it seams that there are some inconsistent logic.

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

> jQuery.merge() is the only function that discards comment nodes (?).
>
> This means that
>
>   $( nodeList )
>
> can contains comment nodes, but
>
>   $([]).add( nodeList  )
>
> can not.
>
> Why such different behaviors?
> Is the jQuery.makeArray() more appropriate to filter comment nodes?
> Am I missing something here?

--

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: $(nodeList) and comment nodes

by John Resig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think you're right here - I'm not completely convinced that this
distinction still needs to exist. Could you file a ticket? Thanks.

--John



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

> To be more accurate,
>
>  $([]).add( nodeList  )
>
> can not contains comment nodes only on IE.
> This makes it even more ambiguous, with unexpected results.
> Also it seams that the only expected NodeList is from an
> getElementsByTagName.call.
>
> I know that it is not explicitly supported by the API, but even then
> it seams that there are some inconsistent logic.
>
> On Oct 30, 6:28 am, Robert Katić <robert.ka...@...> wrote:
>> jQuery.merge() is the only function that discards comment nodes (?).
>>
>> This means that
>>
>>   $( nodeList )
>>
>> can contains comment nodes, but
>>
>>   $([]).add( nodeList  )
>>
>> can not.
>>
>> Why such different behaviors?
>> Is the jQuery.makeArray() more appropriate to filter comment nodes?
>> Am I missing something here?
>
> --
>
> 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: $(nodeList) and comment nodes

by Karl Swedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I came across an oddity with jQuery.merge from a completely different route -- looking through jQuery.support properties. It looks like jQuery.merge is testing for jQuery.support.getAll, but I can't for the life of me find anywhere in the source where jQuery.support.getAll is being defined.  

Since jQuery.support.getAll is never true (because it's not defined), comments are always excluded (   if ( elem.nodeType !== 8 )   ).

Did jQuery at one point define jQuery.support.getAll? And if so, what was it based on?

from core.js line 442 (in github version just pulled this morning): 

merge: function( first, second ) {
// We have to loop this way because IE & Opera overwrite the length
// expando of getElementsByTagName
var i = 0, elem, pos = first.length;

// Also, we need to make sure that the correct elements are being returned
// (IE returns comment nodes in a '*' query)
if ( !jQuery.support.getAll ) {
while ( (elem = second[ i++ ]) != null ) {
if ( elem.nodeType !== 8 ) {
first[ pos++ ] = elem;
}
}

} else {
while ( (elem = second[ i++ ]) != null ) {
first[ pos++ ] = elem;
}
}

return first;
}


--Karl

____________
Karl Swedberg




On Oct 30, 2009, at 10:31 AM, John Resig wrote:

I think you're right here - I'm not completely convinced that this
distinction still needs to exist. Could you file a ticket? Thanks.

--John



On Fri, Oct 30, 2009 at 7:47 AM, Robert Katić <robert.katic@...> wrote:
To be more accurate,

 $([]).add( nodeList  )

can not contains comment nodes only on IE.
This makes it even more ambiguous, with unexpected results.
Also it seams that the only expected NodeList is from an
getElementsByTagName.call.

I know that it is not explicitly supported by the API, but even then
it seams that there are some inconsistent logic.

On Oct 30, 6:28 am, Robert Katić <robert.ka...@...> wrote:
jQuery.merge() is the only function that discards comment nodes (?).

This means that

  $( nodeList )

can contains comment nodes, but

  $([]).add( nodeList  )

can not.

Why such different behaviors?
Is the jQuery.makeArray() more appropriate to filter comment nodes?
Am I missing something here?

--

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.



--

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: $(nodeList) and comment nodes

by John Resig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eww... It must've been accidentally cut in the last release - but we
didn't notice because the "worst case" is only a minor perf hit. Well,
it makes it pretty easy to actually just remove it then! (Especially
if the only place where it's being used internally is in this
soon-to-be-stripped method.)

I'll be sure to revise the docs when I make the cut as well.

--John



On Fri, Oct 30, 2009 at 11:52 AM, Karl Swedberg <karl@...> wrote:

> I came across an oddity with jQuery.merge from a completely different route
> -- looking through jQuery.support properties. It looks like jQuery.merge is
> testing for jQuery.support.getAll, but I can't for the life of me find
> anywhere in the source where jQuery.support.getAll is being defined.
> Since jQuery.support.getAll is never true (because it's not defined),
> comments are always excluded (   if ( elem.nodeType !== 8 )   ).
> Did jQuery at one point define jQuery.support.getAll? And if so, what was it
> based on?
> from core.js line 442 (in github version just pulled this morning):
> merge: function( first, second ) {
> // We have to loop this way because IE & Opera overwrite the length
> // expando of getElementsByTagName
> var i = 0, elem, pos = first.length;
> // Also, we need to make sure that the correct elements are being returned
> // (IE returns comment nodes in a '*' query)
> if ( !jQuery.support.getAll ) {
> while ( (elem = second[ i++ ]) != null ) {
> if ( elem.nodeType !== 8 ) {
> first[ pos++ ] = elem;
> }
> }
> } else {
> while ( (elem = second[ i++ ]) != null ) {
> first[ pos++ ] = elem;
> }
> }
> return first;
> }
>
> --Karl
> ____________
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
>
>
>
> On Oct 30, 2009, at 10:31 AM, John Resig wrote:
>
> I think you're right here - I'm not completely convinced that this
> distinction still needs to exist. Could you file a ticket? Thanks.
>
> --John
>
>
>
> On Fri, Oct 30, 2009 at 7:47 AM, Robert Katić <robert.katic@...>
> wrote:
>
> To be more accurate,
>
>  $([]).add( nodeList  )
>
> can not contains comment nodes only on IE.
>
> This makes it even more ambiguous, with unexpected results.
>
> Also it seams that the only expected NodeList is from an
>
> getElementsByTagName.call.
>
> I know that it is not explicitly supported by the API, but even then
>
> it seams that there are some inconsistent logic.
>
> On Oct 30, 6:28 am, Robert Katić <robert.ka...@...> wrote:
>
> jQuery.merge() is the only function that discards comment nodes (?).
>
> This means that
>
>   $( nodeList )
>
> can contains comment nodes, but
>
>   $([]).add( nodeList  )
>
> can not.
>
> Why such different behaviors?
>
> Is the jQuery.makeArray() more appropriate to filter comment nodes?
>
> Am I missing something here?
>
> --
>
> 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.
>
>
>
> --
>
> 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: $(nodeList) and comment nodes

by Robert Katić :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The main culprit of these problems is probably jQuery.makeArray.
It is supposed to convert anything to an array, but how about
NodeLists?
Maybe jQuery.makeArray have to call jQuery.merge internally if a
NodeList is given?
If so, then an jQuery.isNodeList is needed, I suppose.

On Oct 30, 5:01 pm, John Resig <jere...@...> wrote:

> Eww... It must've been accidentally cut in the last release - but we
> didn't notice because the "worst case" is only a minor perf hit. Well,
> it makes it pretty easy to actually just remove it then! (Especially
> if the only place where it's being used internally is in this
> soon-to-be-stripped method.)
>
> I'll be sure to revise the docs when I make the cut as well.
>
> --John
>
> On Fri, Oct 30, 2009 at 11:52 AM, Karl Swedberg <k...@...> wrote:
> > I came across an oddity with jQuery.merge from a completely different route
> > -- looking through jQuery.support properties. It looks like jQuery.merge is
> > testing for jQuery.support.getAll, but I can't for the life of me find
> > anywhere in the source where jQuery.support.getAll is being defined.
> > Since jQuery.support.getAll is never true (because it's not defined),
> > comments are always excluded (   if ( elem.nodeType !== 8 )   ).
> > Did jQuery at one point define jQuery.support.getAll? And if so, what was it
> > based on?
> > from core.js line 442 (in github version just pulled this morning):
> > merge: function( first, second ) {
> > // We have to loop this way because IE & Opera overwrite the length
> > // expando of getElementsByTagName
> > var i = 0, elem, pos = first.length;
> > // Also, we need to make sure that the correct elements are being returned
> > // (IE returns comment nodes in a '*' query)
> > if ( !jQuery.support.getAll ) {
> > while ( (elem = second[ i++ ]) != null ) {
> > if ( elem.nodeType !== 8 ) {
> > first[ pos++ ] = elem;
> > }
> > }
> > } else {
> > while ( (elem = second[ i++ ]) != null ) {
> > first[ pos++ ] = elem;
> > }
> > }
> > return first;
> > }
>
> > --Karl
> > ____________
> > Karl Swedberg
> >www.englishrules.com
> >www.learningjquery.com
>
> > On Oct 30, 2009, at 10:31 AM, John Resig wrote:
>
> > I think you're right here - I'm not completely convinced that this
> > distinction still needs to exist. Could you file a ticket? Thanks.
>
> > --John
>
> > On Fri, Oct 30, 2009 at 7:47 AM, Robert Katić <robert.ka...@...>
> > wrote:
>
> > To be more accurate,
>
> >  $([]).add( nodeList  )
>
> > can not contains comment nodes only on IE.
>
> > This makes it even more ambiguous, with unexpected results.
>
> > Also it seams that the only expected NodeList is from an
>
> > getElementsByTagName.call.
>
> > I know that it is not explicitly supported by the API, but even then
>
> > it seams that there are some inconsistent logic.
>
> > On Oct 30, 6:28 am, Robert Katić <robert.ka...@...> wrote:
>
> > jQuery.merge() is the only function that discards comment nodes (?).
>
> > This means that
>
> >   $( nodeList )
>
> > can contains comment nodes, but
>
> >   $([]).add( nodeList  )
>
> > can not.
>
> > Why such different behaviors?
>
> > Is the jQuery.makeArray() more appropriate to filter comment nodes?
>
> > Am I missing something here?
>
> > --
>
> > 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.
>
> > --
>
> > 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.