File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1010
1111## My JavaScript Demos - I Love JavaScript!
1212
13+ * [ Using : scope To Identify The Host Element In A CSS Selector] ( https://bennadel.github.io/JavaScript-Demos/demos/scope-pseudo-class )
1314* [ Comparing Undefined Values In JavaScript] ( https://bennadel.github.io/JavaScript-Demos/demos/undefined-comparison )
1415* [ Using The Button Form Attribute To Create Standalone Buttons In HTML] ( https://bennadel.github.io/JavaScript-Demos/demos/link-buttons )
1516* [ Box Breathing Exercise With SpeechSynthesis And Alpine.js] ( https://bennadel.github.io/JavaScript-Demos/demos/box-breathing-alpine )
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html lang ="en ">
3+ < link rel ="stylesheet " type ="text/css " href ="./main.css " />
4+ < body >
5+
6+ < h1 >
7+ Using :scope To Identify The Host Element In A CSS Selector
8+ </ h1 >
9+
10+ < p onclick ="selectOdds( event ) ">
11+ < span > < em > 1</ em > </ span >
12+ < span > < em > 2</ em > </ span >
13+ < span > < em > 3</ em > </ span >
14+ < span > < em > 4</ em > </ span >
15+ < span > < em > 5</ em > </ span >
16+ < span > < em > 6</ em > </ span >
17+ < span > < em > 7</ em > </ span >
18+ < span > < em > 8</ em > </ span >
19+ < span > < em > 9</ em > </ span >
20+ < span > < em > 10</ em > </ span >
21+ </ p >
22+
23+ < script type ="text/javascript ">
24+
25+ function selectOdds ( event ) {
26+
27+ var targets = event
28+ . currentTarget
29+ // In the selector, ":scope" represents the current element on which the
30+ // query is being called. This allows us to use the direct-descendant
31+ // operator since it gives us a way to identify the parent of the direct
32+ // descendants.
33+ . querySelectorAll ( ":scope > :nth-child( odd )" )
34+ ;
35+
36+ for ( var node of targets ) {
37+
38+ node . style = "background-color: hotpink ; color: white ;" ;
39+
40+ }
41+
42+ }
43+
44+ </ script >
45+
46+ </ body >
47+ </ html >
Original file line number Diff line number Diff line change 1+
2+ html {
3+ box-sizing : border-box ;
4+ }
5+ html * ,
6+ html * : before ,
7+ html * : after {
8+ box-sizing : inherit ;
9+ }
10+
11+ body {
12+ font-family : monospace ;
13+ font-size : 20px ;
14+ }
15+
16+ p {
17+ display : flex ;
18+ font-size : 30px ;
19+ gap : 10px ;
20+ }
21+ p span {
22+ background-color : # f0f0f0 ;
23+ border-radius : 5px ;
24+ padding : 3px 15px ;
25+ }
26+ p : hover {
27+ outline : 2px solid cyan ;
28+ outline-offset : 3px ;
29+ }
You can’t perform that action at this time.
0 commit comments