Last active
February 16, 2020 17:55
-
-
Save cognominal/acad326b63bfd4f9a34ac6b14c0749cf to your computer and use it in GitHub Desktop.
sekret
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="f" class='root'> | |
<div id="g"> | |
<div id="k">foo</div> | |
</div> | |
</div> | |
<div id='diag'> | |
kkkkk | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": [], | |
"styles": [] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let elt = document.querySelector('#k') | |
let diag = document.querySelector('#diag') | |
function log(s) { | |
diag.appendChild(document.createTextNode( s + ' ')) | |
} | |
log(elt) | |
function getParent(elt, sel) { | |
let dad | |
let putativeParents = document.querySelectorAll(sel) | |
dad = elt | |
while(1) { | |
dad = dad.parentNode | |
for (e of putativeParents) { | |
if (e == dad) { return dad } | |
} | |
if (dad.tagName == 'HTML') { break } | |
} | |
alert('fail') | |
} | |
let dad = getParent(elt, '#f') | |
log(dad) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#diag { color: red } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment