File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > DOM in Js</ title >
7+ < link rel ="stylesheet " href ="style.css "/>
8+ </ head >
9+ < body >
10+ < h1 class ="heading-class "> Dom Demo by Nilaj</ h1 >
11+ < h1 class ="heading-class "> Dom Demo In JS</ h1 >
12+ < h4 > Topic 1 : Starter Code</ h4 >
13+ < p > Let's learn about Dom concepts in Js </ p >
14+ < p > 2nd Paragraph </ p >
15+ < button id ="btn "> Click Me ..!</ button >
16+ < h3 style ="visibility: hidden; "> This is heading 3</ h3 >
17+ < div >
18+ < h3 > Fruits</ h3 >
19+ < ul >
20+ < li > Mango</ li >
21+ < li > Apple</ li >
22+ < li > Litchi</ li >
23+ </ ul >
24+ </ div >
25+ < script src ="script.js "> </ script >
26+ </ body >
27+ </ html >
Original file line number Diff line number Diff line change 1+ let h2 = document . querySelector ( "h2" ) ;
2+ console . dir ( h2 . innerText ) ;
3+ h2 . innerText = h2 . innerText + "from Apna College student" ;
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Practice 1</ title >
7+ </ head >
8+ < body >
9+ < h2 > Hello JavaScript</ h2 >
10+
11+ </ body >
12+ < script src ="practice.js "> </ script >
13+ </ html >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Practice 2</ title >
7+ < link rel ="stylesheet " href ="style1.css "/>
8+ </ head >
9+ < body >
10+ < h2 > Hello JavaScript</ h2 >
11+ < div class ="box "> First div</ div >
12+ < div class ="box "> Second div</ div >
13+ < div class ="box "> Third div</ div >
14+ </ body >
15+ < script src ="practice2.js "> </ script >
16+ </ html >
Original file line number Diff line number Diff line change 1+ let divs = document . querySelectorAll ( ".box" ) ;
2+ let idx = 1 ;
3+ for ( div of divs ) {
4+ div . innerText = `new unique value ${ idx } ` ;
5+ idx ++ ;
6+ }
7+
Original file line number Diff line number Diff line change 1+ console . log ( "Document Object Model" ) ;
2+ console . dir ( document ) ; //document
3+ console . dir ( document . body ) ;
4+ console . log ( document . body ) ;
5+
6+ let heading = document . getElementById ( "heading" ) ;
7+ console . log ( heading ) ;
8+
9+
10+ let headings = document . getElementsByClassName ( "heading-class" ) ;
11+ console . dir ( headings ) ;
12+ console . log ( headings ) ;
13+
14+
15+ let paras = document . getElementsByTagName ( "p" ) ;
16+ console . log ( paras ) ;
17+
18+
19+ let firstele = document . querySelector ( "p" ) ;
20+ console . log ( firstele ) ;
21+
22+ let allele = document . querySelectorAll ( "p" ) ;
23+ console . log ( allele ) ;
24+
25+
26+ let btn = document . querySelector ( "#btn" ) ;
27+ console . dir ( btn ) ;
28+ console . log ( btn ) ;
29+ console . log ( btn . tagName ) ;
30+
31+
32+ let div = document . querySelector ( "div" ) ;
33+ console . dir ( div )
34+ console . log ( div . innerText ) ;
35+
36+
37+ let h3 = document . querySelector ( "h3" ) ;
Original file line number Diff line number Diff line change 1+ .heading-class {
2+ color : blue;
3+ text-decoration : "line-through" ;
4+ background-color : yellow;
5+ }
6+
7+ h4 {
8+ color : brown;
9+ }
10+
11+ body {
12+ background-color : pink;
13+ }
14+
15+ button {
16+ background-color : blue;
17+ color : white;
18+ }
Original file line number Diff line number Diff line change 1+ .box {
2+ height : 100px ;
3+ width : 100px ;
4+ border : 1px solid black;
5+ margin : 5px ;
6+ text-align : center;
7+ background-color : aquamarine;
8+ }
You can’t perform that action at this time.
0 commit comments