diff --git a/CHANGELOG b/CHANGELOG index f1d99bf..31a86cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Optimize Element#immediateDescendants. (kangax, Tobie Langel) + * Remove unnecessary function object creation and `Number#times` in `Element._getContentFromAnonymousElement`. (kangax) * Eliminate runtime forking and long method lookup in `Element.hasAttribute`. (kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index 6489c4f..9ba4659 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -536,10 +536,14 @@ Element.Methods = { * **This method is deprecated, please see [[Element.childElements]]**. **/ immediateDescendants: function(element) { - if (!(element = $(element).firstChild)) return []; - while (element && element.nodeType != 1) element = element.nextSibling; - if (element) return [element].concat($(element).nextSiblings()); - return []; + var results = [], child = $(element).firstChild; + while (child) { + if (child.nodeType === 1) { + results.push(Element.extend(child)); + } + child = child.nextSibling; + } + return results; }, /**