Dom Node List
Dom Node List
Removing te span tag content in the webpage and checking behind scene
like given image
<body>
<div class="background">
<h1 id="title" class="heading" >dom le <span style="display:
none;">testksd</span>arning </h1>
<p>Lorem ipsum dolor Lorem ipsum <span>aahsnanjsnnajdnj</span> dtur
adipisicing. sit amet.</p>
</div>
</body>
</ht
Queryselctor selects all tags which want to select if there are multiple
Query selections are like css properties
<input type="password" name="" id="">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
Here the give below example are like changing the colours and using
query selector as a dom and by the hep of css
Arrays and nodelist are di erent which nodelist doesn’t shows any map
prototype and arrays shows all the prototypes
Shown below
In arrays we will get all prototypes
HOW TO CTREATE NEW ELEMENT IN
DOM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="/sc.css">
</head>
<body>
<div class="parent">
<div class="day">monday</div>
<div class="day"> tuesday</div>
<div class="day">wednesday</div>
<div class="day">thursday</div>
</div>
</body>
<script>
const parent=document.querySelector('.parent')
console.log(parent);
</script>
</html>
<script>
const parent=document.querySelector('.parent')
console.log(parent);
console.log(parent.children);
console.log(parent.children[1]);
console.log(parent.children[1].innerHTML);
</script>
for (let i = 0; i < parent.children.length; i++) {
console.log(parent.children[i].innerHTML);
parent.children[1].style.color ="orange"
console.log(parent.firstElementChild);
const dayone =document.querySelector('.day')
console.log(dayone);
console.log(dayone.parentElement);
console.log(dayone.nextElementSibling);
console.log("NODES:",parent.childNodes)
</script>
Here lety create by using document creation
const addText = document.createTextNode("shaheed")
div.appendChild(addText)
document.body.appendChild(div)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOMLEARNING</title>
</head>
<body style="background-color: #212121; color: #fff;">
<ul class="language">
<li>Javascript</li>
</ul>
</body>
<script>
function addLanguage(langName){
const li = document.createElement('li');
li.innerHTML = `${langName}`
document.querySelector('.language').appendChild(li)
}
addLanguage("python")
addLanguage("typescript")
function addOptiLanguage(langName){
const li = document.createElement('li');
li.appendChild(document.createTextNode(langName))
document.querySelector('.language').appendChild(li)
}
addOptiLanguage('golang')
//Edit
const secondLang = document.querySelector("li:nth-child(2)")
console.log(secondLang);
//secondLang.innerHTML = "Mojo"
const newli = document.createElement('li')
newli.textContent = "Mojo"
secondLang.replaceWith(newli)
//edit
const firstLang = document.querySelector("li:first-child")
firstLang.outerHTML = '<li>TypeScript</li>'
//remove
const lastLang = document.querySelector('li:last-child')
lastLang.remove()
</script>
</html>