Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
added parentElement
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Jan 23, 2021
1 parent 060f5ab commit d830694
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Node.js
Expand Up @@ -141,6 +141,11 @@ class Node extends EventTarget {
return null;
}

get parentElement() {
const {parentNode} = this;
return parentNode && parentNode.nodeType === 1 ? parentNode : null;
}

get previousSibling() {
if (this.parentNode) {
const cn = this.parentNode.childNodes;
Expand Down
2 changes: 2 additions & 0 deletions test/all.js
Expand Up @@ -848,6 +848,8 @@ log('## siblings');
let ol = document.createElement('ol');
let li = document.createElement('li');
ol.appendChild(li);
assert(li.parentElement === ol, 'parentElement');
assert(ol.parentElement === null, 'parentElement');
assert(li.previousElementSibling === null, 'null previousElementSibling');
assert(li.nextElementSibling === null, 'null nextElementSibling');
ol.insertBefore(document.createElement('li'), li);
Expand Down
2 changes: 1 addition & 1 deletion web.js

Large diffs are not rendered by default.

0 comments on commit d830694

Please sign in to comment.