File tree Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change 1
1
// getAttribute();
2
2
// setAttribute();
3
3
4
- const first = document . querySelector ( '.first' ) ;
5
- // getAttribute
6
- const getIDs = first . getAttribute ( 'id' ) ;
7
- console . log ( getIDs ) ;
4
+ const heading = document . querySelector ( '.title' ) ;
5
+ // getAttribute class and id from h2
6
+ const classValue = heading . getAttribute ( 'class' ) ;
7
+ const idsValue = heading . getAttribute ( 'id' ) ;
8
+ console . log ( classValue ) ; // show title class
9
+ console . log ( idsValue ) ; //show titles id
10
+
11
+ // setAttribute
12
+ // first move to p cz no have class
13
+ const nextoP = heading . nextElementSibling . nextElementSibling ;
14
+ nextoP . setAttribute ( 'id' , 'text' ) ;
15
+ nextoP . textContent = 'This is a text' ;
16
+
17
+ // example again showLinks
18
+ const links = document . querySelector ( '.links' ) ;
19
+ const getLinks = links . getAttribute ( 'href' ) ;
20
+ console . log ( getLinks ) ;
Original file line number Diff line number Diff line change @@ -83,9 +83,20 @@ <h2>The Pirates</h2>
83
83
<li>marine ford</li>
84
84
</ul> -->
85
85
86
- <!-- textContent and childNodes -->
86
+ <!-- textContent and childNodes
87
87
<h3>Hello people</h3>
88
- < h2 > Hello World</ h2 >
88
+ <h2>Hello World</h2> -->
89
+
90
+ <!-- getAttribute, setAttribute -->
91
+ < div class ="container ">
92
+ < h2 class ="title " id ="titles "> Hello World</ h2 >
93
+ < a href ="index.html " class ="links "> This Links</ a >
94
+ < p >
95
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam,
96
+ doloribus!
97
+ </ p >
98
+ </ div >
99
+
89
100
<!-- source js -->
90
101
<!-- <script src="/01_getElementById.js"></script> -->
91
102
<!-- <script src="/02_getElementByTagName.js"></script> -->
@@ -95,7 +106,7 @@ <h2>Hello World</h2>
95
106
<!-- <script src="/06_parentElement.js"></script> -->
96
107
<!-- <script src="/07_nextSibling_previous.js"></script> -->
97
108
<!-- <script src="/08_nextElementSibling_previous.js"></script> -->
98
- < script src ="/09_textContent.js "> </ script >
99
- <!-- < script src="/10_getAttribute.js"></script> -- >
109
+ <!-- < script src="/09_textContent.js"></script> -- >
110
+ < script src ="/10_getAttribute.js "> </ script >
100
111
</ body >
101
112
</ html >
You can’t perform that action at this time.
0 commit comments