DOM Manipulation Interview Questions

    Question 1: Accessing Element by ID

    Which method is used to get an element by its ID?

    Question 2: Accessing Multiple Elements

    Which method returns a live HTMLCollection of elements with a given class name?

    Question 3: Modifying Text Content

    How do you change the text inside an element with ID title?

    Question 4: Creating Elements

    Which method creates a new HTML element?

    Question 5: Appending Elements

    How do you add a newly created element p to the body?

    Question 6: Changing Attributes

    How can you change the src attribute of an image with ID pic?

    Question 7: Removing Elements

    Which method removes a child node from the DOM?

    Question 8: Event Listener

    How do you add a click event listener to a button with ID btn?

    Question 9: Query Selector

    Which method selects the first element that matches a CSS selector?

    Question 10: querySelectorAll vs getElementsByClassName

    What is the difference between querySelectorAll and getElementsByClassName?