From 64f8be1dd359a86d08a2afcd226b588efe528a44 Mon Sep 17 00:00:00 2001 From: lalala Date: Tue, 5 Nov 2019 12:42:04 +0100 Subject: [PATCH] add firstElementChild to Node prototype --- dom.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dom.js b/dom.js index b13b371..47a55f6 100644 --- a/dom.js +++ b/dom.js @@ -310,6 +310,7 @@ function Node() { }; Node.prototype = { + firstElementChild: null, firstChild : null, lastChild : null, previousSibling : null, @@ -494,6 +495,7 @@ function _removeChild(parentNode,child){ parentNode.lastChild = previous; } _onUpdateChild(parentNode.ownerDocument,parentNode); + _updateFirstElementChild(parentNode); return child; } /** @@ -537,6 +539,7 @@ function _insertBefore(parentNode,newChild,nextChild){ if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) { newChild.firstChild = newChild.lastChild = null; } + _updateFirstElementChild(parentNode); return newChild; } function _appendSingleChild(parentNode,newChild){ @@ -557,9 +560,23 @@ function _appendSingleChild(parentNode,newChild){ } parentNode.lastChild = newChild; _onUpdateChild(parentNode.ownerDocument,parentNode,newChild); + _updateFirstElementChild(parentNode); return newChild; //console.log("__aa",parentNode.lastChild.nextSibling == null) } +function _updateFirstElementChild(parentNode){ + parentNode.firstElementChild = null; + if(parentNode.childNodes && parentNode.childNodes.length){ + for(var i=0; i