Skip to content

Commit 688acbc

Browse files
committed
Add support for Element#nextSibling / Element#previousSibling
1 parent 047fa0a commit 688acbc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/undom.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ const NODE_TYPES = {
2424
* @returns {Document} document
2525
*/
2626
export default function undom() {
27+
28+
function sibling(node, offset) {
29+
let p = node.parentNode;
30+
if (p) return p.childNodes[findWhere(p.childNodes, node, true) + offset];
31+
}
32+
2733
class Node {
2834
constructor(nodeType, nodeName) {
2935
this.nodeType = nodeType;
3036
this.nodeName = nodeName;
3137
this.childNodes = [];
3238
}
39+
get nextSibling() {
40+
return sibling(this, 1);
41+
}
42+
get previousSibling() {
43+
return sibling(this, -1);
44+
}
3345
appendChild(child) {
3446
child.remove();
3547
child.parentNode = this;

0 commit comments

Comments
 (0)