|
| 1 | +/* Access by tag, class, ID */ |
| 2 | +document.getElementById('demo').innerHTML = 'Hello Javascript!! I am Id'; |
| 3 | +document.getElementsByClassName('demo1')[0].innerHTML = 'Hello, I am a class'; |
| 4 | +document.getElementsByTagName('div')[1].innerHTML = 'Hello i am a div'; |
| 5 | +// const paragraph = document.querySelector("p"); |
| 6 | +// setTimeout(() => { |
| 7 | +// paragraph.innerHTML = 'Hello this is change to query selector'; |
| 8 | +// paragraph.style.backgroundColor = 'red'; |
| 9 | +// }, 2000) |
| 10 | + |
| 11 | + |
| 12 | +/**** Attribite ****/ |
| 13 | +// const attributes = paragraph.attributes; |
| 14 | +// console.log(attributes[1]) |
| 15 | +// let link = document.getElementById('hrefLink'); |
| 16 | +// link.removeAttribute("target"); |
| 17 | +// link.setAttribute('href', 'https://www.gmail.com'); |
| 18 | +// console.log(link.getAttribute('href')) |
| 19 | +// let x = document.getElementById('hrefLink'); |
| 20 | +// x.href = 'https://www.gmail.com'; |
| 21 | + |
| 22 | + |
| 23 | +/**** Custom Tag creation ****/ |
| 24 | +let sec = document.createElement('section'); |
| 25 | +sec.setAttribute('id', 'secId'); |
| 26 | +let secP = document.createElement('p'); |
| 27 | +let secPTxt = document.createTextNode('Custom p tag text node'); |
| 28 | +secP.appendChild(secPTxt); |
| 29 | +let secDiv = document.createElement('div'); |
| 30 | +let secDivNode = document.createTextNode('Custom div tag text node') |
| 31 | +secDiv.appendChild(secDivNode); |
| 32 | +sec.appendChild(secP); |
| 33 | +sec.appendChild(secDiv); |
| 34 | +document.body.append(sec); |
| 35 | + |
| 36 | +/**** Remove child node ****/ |
| 37 | +// let pId = document.getElementById('demo'); |
| 38 | +// pId.parentNode.removeChild(pId); |
| 39 | +// let prId = document.getElementById('parntId'); |
| 40 | +// let chId = document.getElementById('chldId'); |
| 41 | +// let btnClick = document.getElementById('clickId'); |
| 42 | +// btnClick.addEventListener('click', function(){ |
| 43 | +// prId.removeChild(chId); |
| 44 | +// }) |
| 45 | + |
| 46 | + |
| 47 | +/**** Replace node ****/ |
| 48 | +// let getParntId = document.getElementById('parntId'); |
| 49 | +// let getChild = document.getElementById('chldId'); |
| 50 | +// let getNewChild = document.getElementById('newChldId'); |
| 51 | +// let btnClick = document.getElementById('clickId'); |
| 52 | +// btnClick.addEventListener('click', function(){ |
| 53 | +// getParntId.replaceChild(getChild, getNewChild); |
| 54 | +// }) |
| 55 | + |
| 56 | + |
| 57 | +/**** Event handler ****/ |
| 58 | +let btnClick = document.getElementById('clickId'); |
| 59 | +// btnClick.onclick = function(){ |
| 60 | +// console.log('Onclick event call') |
| 61 | +// } |
| 62 | +btnClick.style.backgroundColor = 'red'; |
| 63 | +btnClick.style.color = 'white'; |
| 64 | +btnClick.style.padding = '10px'; |
| 65 | +btnClick.style.border = 'none'; |
| 66 | +// btnClick.onmouseover = function(){ |
| 67 | +// this.innerHTML = 'Remove Tests'; |
| 68 | +// btnClick.style.backgroundColor = 'green'; |
| 69 | +// } |
| 70 | +// btnClick.onmouseout = function(){ |
| 71 | +// this.innerHTML = 'Remove Node'; |
| 72 | +// btnClick.style.backgroundColor = 'red'; |
| 73 | +// } |
| 74 | +// btnClick.addEventListener('click', function(){ |
| 75 | +// let xtrTxt = document.createTextNode(' Submit') |
| 76 | +// btnClick.appendChild(xtrTxt); |
| 77 | +// // }) |
| 78 | +// btnClick.addEventListener('mousedown', function(){ |
| 79 | +// btnClick.style.backgroundColor = 'green'; |
| 80 | +// }) |
| 81 | +// btnClick.addEventListener('mouseup', function(){ |
| 82 | +// btnClick.style.backgroundColor = 'red'; |
| 83 | +// }) |
| 84 | + |
| 85 | +btnClick.addEventListener('focusin', function(){ |
| 86 | + btnClick.style.border = '1px solid #000'; |
| 87 | +}) |
| 88 | +btnClick.addEventListener('focusout', function(){ |
| 89 | + btnClick.style.border = 'none'; |
| 90 | +}) |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +/**** Query selector ****/ |
| 95 | +// let x = document.querySelectorAll('p')[0].outerHTML; |
| 96 | +// const x = document.forms["frm1"]; |
| 97 | +// console.log(x); |
| 98 | + |
| 99 | +// let btnClick = document.getElementById('clickId'); |
| 100 | +// btnClick.onclick = function(){ |
| 101 | +// let x = document.scripts[0]; |
| 102 | +// x.setAttribute('src', 'https://www.gmail.com'); |
| 103 | +// } |
| 104 | + |
| 105 | + |
| 106 | +/**** Form Validation ****/ |
| 107 | +// let btnClick = document.getElementById('submitForm'); |
| 108 | +// btnClick.onclick = function(){ |
| 109 | +// let x = document.forms['frm1']['fname'].value; |
| 110 | +// if(!!!x){ |
| 111 | +// alert('please enter value') |
| 112 | +// } |
| 113 | +// return false; |
| 114 | +// } |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
0 commit comments