|
| 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>Create a new elemenet</title> |
| 7 | + </head> |
| 8 | + <body style="background-color: #212121; color: #fff"> |
| 9 | + <div class="parent"> |
| 10 | + <div class="day">Monday</div> |
| 11 | + <div class="day">Tuesday</div> |
| 12 | + <div class="day">Wednesday</div> |
| 13 | + <div class="day">Thursday</div> |
| 14 | + </div> |
| 15 | + |
| 16 | + <script> |
| 17 | + // console.log("is js working"); |
| 18 | + const parent = document.querySelector(".parent"); |
| 19 | + // console.log(parent); |
| 20 | + // console.log(parent.children); |
| 21 | + // console.log(parent.children[0]); |
| 22 | + |
| 23 | + for (let i = 0; i < parent.children.length; i++) { |
| 24 | + // console.log(parent.children[i]); |
| 25 | + } |
| 26 | + // console.log(parent.children[0].innerHTML); |
| 27 | + |
| 28 | + // console.log(parent.firstElementChild); |
| 29 | + // console.log(parent.lastElementChild); |
| 30 | + |
| 31 | + const firstElem = document.querySelector(".day"); |
| 32 | + //console.log(firstElem); |
| 33 | + // console.log(firstElem.children); //length is 0 |
| 34 | + |
| 35 | + //console.log(firstElem.parentElement); |
| 36 | + //console.log(firstElem.nextElementSibling.nextElementSibling); //wednesday |
| 37 | + //console.log(firstElem.lastElementChild); //null |
| 38 | + // console.log(`Nodes ${parent.childNodes}`); |
| 39 | + console.log("Nodes", parent.childNodes); |
| 40 | + </script> |
| 41 | + </body> |
| 42 | +</html> |
0 commit comments