4

TIL that you can use the :scope pseudo class to select direct children of an ele...

 2 years ago
source link: https://www.matuzo.at/til/til47/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

TIL that you can use the :scope pseudo class to select direct children of an element with .querySelectorAll().

This site is updating in the open

Things might look unstyled because they probably are.

TIL that you can use the :scope pseudo class to select direct children of an element with .querySelectorAll().

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>

<p>D</p>
  console.log(document.body.querySelectorAll('*'))
// NodeList(5) [ul, li, li, li, p]

console.log(document.body.querySelectorAll(':scope > *'))
// NodeList(2) [ul, p]

https://codepen.io/pen/?editors=1001

© 2019 - 2022

Back to top


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK