MethodsΒΆ
- when HTML page loads in browser, browser created object which models document on page which is called as document object
- Step 01: using the createElement method
var element = document.createElement("div"); // <div><div>
- //step 02: add the content
element.innerHTML = "this is div"; //<div>this is div</div> -
//Step 03: need to add newly created element to body
-
``` document.body.append(element); ------------ or Const body = document.body //you can use this body const n number of times to save typing document.body every time body.append(element)
```
-
Append Vs appendChild()
body.append() =append element + textbody.append('Hello','username')
body.appendChild() =append only element no text
-
remove Vs removeChild()
- setAttributes
- removeAttribute
- querySelector Vs querySelectorAll
document.querySelectorAll(".name-list li") - Styling Element
- const ele = document.querySelector(".container") //.container is class name
- ele.classList.add("classname")
- ele.classList.remove("classname")
- const ele = document.querySelector("#id")
-
Window & document objectΒΆ