DEV Community

Akash
Akash

Posted on

Interview Questions about DOM in Javascript

1.What is Dom ?

  • DOM refers to Document Object Model,It allows javascript to modify,Access,delete elements dynamically.

2.How do you select an elements in DOM ?

  • For selecting id document.getElementById("id");
  • For selecting class document.getElementByClassName("classname");
  1. Difference between getElementById and querySelector
  • getElementById simply selects id,if the document has many element it needs to specific element to pointout and select.
  • querySelector selects a first element of declared element.

4.Difference between innerHTML and innertext ?

  • innerHTML gets HTML contents with tags interpreted
    e.g(it prints along with tag

    happy birthday

    )
  • innerText gets only text
    (e.g) it prints only text happy birthday

5.How to create new DOM element ?

  • for creating element in dom use document.createElement (e.g) let element = document.createElement("p");

6.How to remove element in DOM ?

  • for removing element in DOM use document.getElementByTagName (e.g) document.getElementByTagName("p").remove();
  1. How do change CSS style using DOM ?
  • By using style property we can access or change CSS style in DOM (e.g) document.getElementByTagName("h1").style.color="red"; document.getElementByTagName("h1").style.color="green";

8.What is Event Delegation and Event Bubbling in DOM ?(TBD)

Top comments (0)