Skip to content

MethodsΒΆ

  1. when HTML page loads in browser, browser created object which models document on page which is called as document object
  2. Step 01: using the createElement method
var element = document.createElement("div"); // <div><div>
  1. //step 02: add the content
    element.innerHTML = "this is div"; //<div>this is div</div>
    
  2. //Step 03: need to add newly created element to body

  3. ``` 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)

    ```

  4. Append Vs appendChild()

    1. body.append() = append element + text
      1. body.append('Hello','username')
    2. body.appendChild() = append only element no text
  5. remove Vs removeChild()

  6. setAttributes
  7. removeAttribute
  8. querySelector Vs querySelectorAll
    document.querySelectorAll(".name-list li")
    
  9. Styling Element
  10. const ele = document.querySelector(".container") //.container is class name
  11. ele.classList.add("classname")
  12. ele.classList.remove("classname")
  13. const ele = document.querySelector("#id")
  14. Window & document objectΒΆ