4 ms·
Nice work! The only advice I’d give is don’t use patterns like div.parentElement.parentElement.foo() It’s inflexible and will break if you ever make dom c
by jjcm 6y ago
Nice work! The only advice I’d give is don’t use patterns like
div.parentElement.parentElement.foo()
It’s inflexible and will break if you ever make dom changes. Use the .closest() selector instead. It’s like a reverse .querySelector (.closest selects ancestors, .querySelector selects descendents) which means you’ll have more specific code.
- soylentgraham 6y agoTIL about .closest! From the article.