File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 1
1
<!DOCTYPE html>
2
2
< html lang ="en ">
3
+
3
4
< head >
4
5
< meta charset ="UTF-8 ">
5
6
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
11
12
}
12
13
</ style >
13
14
</ head >
15
+
14
16
< body >
15
17
< tab-panel >
16
18
< div data-tabname ="one "> Tab one</ div >
17
19
< div data-tabname ="two "> Tab two</ div >
18
20
< div data-tabname ="three "> Tab three</ div >
19
21
</ tab-panel >
20
22
< script >
21
-
23
+
22
24
function asTabs ( node ) {
23
25
const children = Array . from ( node . children ) ;
26
+ const header = document . createElement ( 'header' ) ;
27
+ document . body . insertBefore ( header , document . querySelector ( 'tab-panel' ) ) ;
24
28
25
29
function manageSelection ( event ) {
26
30
if ( document . querySelector ( '.selected' ) ) {
33
37
if ( childNode . style . display === 'block' ) {
34
38
childNode . style . display = 'none' ;
35
39
}
36
- if ( childNode . getAttribute ( 'data-tabname' ) === event . target . textContent ) {
40
+ if ( childNode . getAttribute ( 'data-tabname' ) === event . target . textContent ) {
37
41
childNode . style . display = 'block'
38
42
}
39
43
} )
43
47
const button = document . createElement ( 'button' ) ;
44
48
button . textContent = childNode . getAttribute ( 'data-tabname' ) ;
45
49
button . addEventListener ( 'click' , manageSelection )
46
- document . body . appendChild ( button ) ;
50
+ document . querySelector ( 'header' ) . appendChild ( button ) ;
47
51
childNode . style . display = 'none' ;
48
52
} )
49
53
50
54
}
51
55
asTabs ( document . querySelector ( "tab-panel" ) ) ;
52
56
</ script >
53
57
</ body >
58
+
54
59
</ html >
You can’t perform that action at this time.
0 commit comments