JavaScript DOM and BOM

Last Updated :
Discuss
Comments

Question 1

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

  • A

    getElementByClass()

  • B

    getElementById()

  • C

    querySelectorAll()

  • D

    getById()

Question 2

What does document.querySelectorAll() return?

  • A

    An array of elements

  • B

    A single element

  • C

    A NodeList

  • D

    Undefined

Question 3

How do you change the inner text of an element in the DOM?

  • A

    element.innerText = "New Text";

  • B

    element.textContent = "New Text";

  • C

    element.innerHTML = "New Text";

  • D

    All of the above

Question 4

What does window.location.href return?

  • A

    The browser's name

  • B

    The URL of the current page

  • C

    The history of visited pages

  • D

    The cookies of the website

Question 5

What is the purpose of window.history.back()?

  • A

    To navigate to the next page in history

  • B

    To reload the current page

  • C

    To navigate to the previous page in history

  • D

    To clear the browser's history

Question 6

Which method is used to set a cookie?

  • A

    document.cookie = "key=value";

  • B

    window.setCookie()

  • C

    navigator.cookie()

  • D

    cookie.set()

Question 7

What will the following code output?

JavaScript
console.log(window.navigator.userAgent);


  • A

    Browser and device information

  • B

    URL of the current page

  • C

    Cookies of the website

  • D

    Undefined

Question 8

Which event is triggered when the DOM is fully loaded?

  • A

    onload

  • B

    DOMContentLoaded

  • C

    load

  • D

    domComplete

Question 9

How do you remove an element from the DOM?

  • A

    element.remove();

  • B

    element.delete();

  • C

    element.destroy();

  • D

    element.clear();

Question 10

What does window.alert() do?

  • A

    Logs a message to the console

  • B

    Shows a confirmation box

  • C

    Displays an alert box with a message

  • D

    Refreshes the browser

There are 10 questions to complete.

Take a part in the ongoing discussion