OneCompiler

Uses of methods and properties in Javascript

97
<!DOCTYPE html> <html> <head> <title>Hello, World!</title> </head> <body> <h1 class="title">oldtitle</h1> <p id="currentTime"></p> <script src="script.js"></script> </body> </html>

function change() {
//for accessing element and updation in element
let element1 = document.querySelector('.title')
let newPara = "kuch bhi "
element1.innerHTML = newPara ;
}
change()

function newChange(){
//for creation of element and adition of content in it
let element = document.createElement('p')
element.textContent = "I love mohit"
document.body.appendChild(element)

// for replacing old element by new one
let newPara = document.createElement('p')
newPara.textContent = "change ye hai"
document.body.replaceChild(newPara , element)
}
newChange()

function newLearn() {
//attributes change jisme class add krdi hai
let newClass = document.querySelector(".title")
newClass.setAttribute('class','newclass')
}
newLearn()

function getPrint(){
//new class jo tumne change kri hai usse acces krke title change kiya
let print = document.querySelector('.newclass')
let newThing = "esa hai class ho gyi change"
print.textContent = newThing
}
getPrint()

function insertWala(){
let newElement2 = document.createElement('p')
let newForm = "text content in para"
newElement2.textContent = newForm
document.body.appendChild(newElement2)

let existingElement = document.querySelector('.newclass')
//existing Element k uprr place ho jayega newElement2
existingElement.insertAdjacentElement('beforebegin' , newElement2)

}

insertWala()