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 11// getAttribute();
22// setAttribute();
33
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>
8383 <li>marine ford</li>
8484 </ul> -->
8585
86- <!-- textContent and childNodes -->
86+ <!-- textContent and childNodes
8787 <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+
89100 <!-- source js -->
90101 <!-- <script src="/01_getElementById.js"></script> -->
91102 <!-- <script src="/02_getElementByTagName.js"></script> -->
@@ -95,7 +106,7 @@ <h2>Hello World</h2>
95106 <!-- <script src="/06_parentElement.js"></script> -->
96107 <!-- <script src="/07_nextSibling_previous.js"></script> -->
97108 <!-- <script src="/08_nextElementSibling_previous.js"></script> -->
98- < script src ="/09_textContent.js "> </ script >
99- <!-- < script src="https://github.com/10_getAttribute.js"></script> -- >
109+ <!-- < script src="https://github.com/09_textContent.js"></script> -- >
110+ < script src ="/10_getAttribute.js "> </ script >
100111 </ body >
101112</ html >
You can’t perform that action at this time.
0 commit comments