If you wanted to do it right, you'd want to do something like this:

jQuery.fn.childNodes = function() {
    return this.pushStack( jQuery.map( this,
"jQuery.makeArray(a.childNodes)" ) );
};

HUGE WARNING! (this is why we don't include this method in jQuery
right now) jQuery does not expect itself to handle non-elements. For
example, if were to do:

$("body").childNodes().css("color", "blue");

It would die with an exception, because you can't set a color on a text node.

In fact, there's already a bug open for this specific feature requeset:
http://dev.jquery.com/ticket/1024

--John

On 4/27/07, Jonathan Sharp <[EMAIL PROTECTED]> wrote:
So we have a situation where we need to clone all of an elements childNodes
(including whitespace & text nodes). The code below is an attempt to add a
childNodes() function that behaves similar to children() except for it
includes the childNodes.

Comments/houghts/suggestions/feedback?

$.fn.childNodes = function() {
    return this.pushStack( this.get(0).childNodes || [] );
};

Cheers,
-js

Reply via email to