|
| 1 | +// # DOM Manipulation # |
| 2 | +let val; |
| 3 | + |
| 4 | +// ## document ## |
| 5 | +val = document; |
| 6 | +val = document.all[0]; |
| 7 | +val = document.all.length; |
| 8 | + |
| 9 | +val = document.head; |
| 10 | +val = document.body; |
| 11 | +val = document.doctype; |
| 12 | +val = document.domain; |
| 13 | +val = document.URL; |
| 14 | +val = document.contentType; |
| 15 | + |
| 16 | +// ### document form ### |
| 17 | +val = document.forms; //get element forms |
| 18 | +val = document.forms[0].id; //get class/id form |
| 19 | +val = document.forms[0].method; //get type method |
| 20 | + |
| 21 | +// ### document links ### |
| 22 | +val = document.links; //get all element a href |
| 23 | +val = document.links[0]; //get element a href |
| 24 | +val = document.links[0].className; // get clss in a href |
| 25 | + |
| 26 | +// ### get document image ### |
| 27 | +val = document.images |
| 28 | + |
| 29 | +// ### get document script ### |
| 30 | +val = document.scripts //get all script |
| 31 | +val = document.scripts[1] //get script |
| 32 | +val = document.scripts[1].getAttribute('src') //get link script |
| 33 | + |
| 34 | +// #### list link script #### |
| 35 | + |
| 36 | +let script= document.scripts; |
| 37 | + |
| 38 | +let scriptArr = Array.from(script); //convert from HTMLCollection to array |
| 39 | + |
| 40 | +scriptArr.forEach(function (script) { |
| 41 | + // console.log(script.getAttribute('src')); |
| 42 | +}) |
| 43 | + |
| 44 | +// console.log(val); |
| 45 | + |
| 46 | + |
| 47 | +// ## get Element By Id |
| 48 | + |
| 49 | +console.log(document.getElementById('task-title')); //get element |
| 50 | +console.log(document.getElementById('task-title').id); //get attribute id in element |
| 51 | +console.log(document.getElementById('task-title').className); //get attribute class in element |
| 52 | + |
| 53 | +const cardHeader = document.getElementById('task-title'); |
| 54 | +// ### Change style by id ### |
| 55 | +cardHeader.style.background = 'black'; //change bg by id |
| 56 | +cardHeader.style.color = 'white'; //change bg by id |
| 57 | + |
| 58 | +// ### Change Content by id ### |
| 59 | +cardHeader.textContent = 'Hello World'; //change Content by id |
| 60 | +cardHeader.innerHTML = '<h2 style="text-align:center;">My Task</h2>' |
| 61 | + |
| 62 | +// ## get Query Select, just take the first query ## |
| 63 | +console.log(document.querySelector('#task-title')); //get element |
| 64 | + |
| 65 | +// ### Change style by Query ### |
| 66 | +document.querySelector('li').style.color = 'red'; //take the first query; |
| 67 | +document.querySelector('li:nth-child(2)').textContent = 'Hello World'; // take the quey as requested; |
| 68 | + |
| 69 | +// ## get Class By Class Name ## |
| 70 | + |
| 71 | +const items = document.getElementsByClassName('list-group-item'); |
| 72 | +items[2].style.color = "blue" |
| 73 | + |
| 74 | +// ## get Element By Tag Name ## |
| 75 | +const buttom = document.getElementsByTagName('button'); |
| 76 | +buttom[1].style.color = "Blue" |
| 77 | +console.log(buttom); |
| 78 | + |
| 79 | +// ## get query selector all ## |
| 80 | +const listLight = document.querySelectorAll('li:nth-child(odd'); //get all query odd |
| 81 | + |
| 82 | +listLight.forEach(function (li, index) { |
| 83 | + li.style.background = '#ccc'; |
| 84 | +}) |
0 commit comments