DOM Notes
Table of contents
No headings in the article.
Full form: Document Object Model
Selection methods:
let id = document.getElementById("idName");
let class = document.getElementsByClassName("className");
let tag = document.getElementsByTagName("tagName");
id.innerText = "Hi there"; (changing the text)
query selector : let qs= document.querySelector("#id \ .class \ tagname");
To manipulate style
- tag[2].style.color = "red";
To manipulate classes
qs.className = "class1";
qs.classList = "class1, class2, class3";
To manipulate attributes
- qs.setAttribute("att1", "att2");
To create an element
let title = document.createElement("h1");
title.className = "pwSkills";
title.style.fontSize = "25px";
title.textContent = "Hello";
document.body.appendChild(title);
To delete an element
let ul = document.querySelector("ul");
let lists = document.quertySelectorAll("li");
for(list of lists){
ul.removeChild(list);
}
Event Listener
document.addEventListener("click",functionToCall);
function functionToCall(){
code to be exectued
}
<button onclick="hey()">Submit</button>
function hey(){
code to be executed}