Unit 6 - Practice Quiz

CSE326

1 What does DOM stand for in the context of Web Development?

A. Data Object Model
B. Document Object Model
C. Digital Ordinance Model
D. Document Oriented Module

2 How does the DOM represent an HTML document?

A. As a linear string
B. As a database table
C. As a tree structure of nodes
D. As a binary file

3 Which object represents the entry point to the DOM?

A. window
B. document
C. root
D. html

4 Which method is used to find an element by its specific ID?

A. document.getElement(id)
B. document.selectId(id)
C. document.getElementById(id)
D. document.findId(id)

5 What does 'document.getElementsByTagName('p')' return?

A. The first paragraph element found
B. A list (HTMLCollection) of all paragraph elements
C. The last paragraph element
D. An error

6 Which method is used to select the first element that matches a specified CSS selector?

A. document.querySelectorAll()
B. document.querySelector()
C. document.getElementBySelector()
D. document.find()

7 How can you change the text content of a specific HTML element?

A. element.content = 'text'
B. element.innerHTML = 'text'
C. element.value = 'text'
D. element.text = 'text'

8 Which property is used to get or set the value of an input field?

A. innerHTML
B. innerText
C. value
D. content

9 What is the correct syntax to change the background color of an element using JavaScript?

A. element.style.backgroundColor = 'red'
B. element.style.background-color = 'red'
C. element.css.background = 'red'
D. element.style.bg = 'red'

10 Which method is used to create a new HTML element?

A. document.addElement()
B. document.createElement()
C. document.newElement()
D. document.makeElement()

11 How do you append a new child node to an existing node?

A. parentNode.insert(newNode)
B. parentNode.appendChild(newNode)
C. parentNode.push(newNode)
D. parentNode.add(newNode)

12 Which method removes a child node from the DOM?

A. parentNode.deleteChild(node)
B. parentNode.remove(node)
C. parentNode.removeChild(node)
D. parentNode.detach(node)

13 What property returns the parent node of an element?

A. element.topNode
B. element.parentNode
C. element.root
D. element.parentElementNode

14 Which event occurs when a user clicks on an HTML element?

A. onmouseover
B. onchange
C. onclick
D. onmouseclick

15 What is the difference between 'innerHTML' and 'innerText'?

A. They are identical.
B. innerHTML parses HTML tags, while innerText treats them as raw text.
C. innerText parses HTML tags, while innerHTML treats them as raw text.
D. innerHTML is read-only.

16 How do you add an event listener to an element?

A. element.attachEvent('click', function)
B. element.addEventListener('click', function)
C. element.on('click', function)
D. element.listen('click', function)

17 Which property allows you to read or change the class of an element as a string?

A. element.class
B. element.className
C. element.cssClass
D. element.classList

18 Which property allows you to add or remove CSS classes easily using methods like .add() and .remove()?

A. element.className
B. element.classList
C. element.style
D. element.classes

19 What does 'document.write()' do?

A. Writes data to a specific element
B. Writes a stream of text to the document stream
C. Writes to the browser console
D. Saves data to a file

20 Which attribute is used to access the attribute value of an HTML element?

A. element.attr(name)
B. element.getAttribute(name)
C. element.fetchAttribute(name)
D. element.attribute(name)

21 How do you set an attribute on an element?

A. element.setAttribute(name, value)
B. element.attr(name, value)
C. element.createAttribute(name, value)
D. element.attribute = value

22 Which event triggers when a web page has finished loading?

A. onready
B. onload
C. onfinish
D. onrender

23 Which property provides the full URL of the current HTML document?

A. document.location
B. document.URL
C. window.link
D. document.href

24 What is the return type of 'document.querySelectorAll'?

A. Array
B. NodeList
C. HTMLCollection
D. String

25 How do you prevent the default behavior of an event (like a form submission)?

A. event.stop()
B. event.halt()
C. event.preventDefault()
D. event.cancel()

26 Which DOM property is used to hide an element using CSS?

A. element.style.visibility = 'hidden'
B. element.style.display = 'none'
C. Both A and B
D. element.style.hidden = true

27 What is the root element of the document.documentElement property?

A. <body>
B. <head>
C. <html>
D. <!DOCTYPE>

28 Which event fires when an input field loses focus?

A. onfocus
B. onblur
C. onchange
D. oninput

29 How can you access the text content of a node and all its descendants?

A. node.text
B. node.textContent
C. node.content
D. node.string

30 What does the 'this' keyword refer to inside an event handler function defined in HTML?

A. The global window object
B. The element that received the event
C. The document object
D. The javascript engine

31 Which method is used to remove an attribute from an element?

A. element.deleteAttribute()
B. element.removeAttribute()
C. element.clearAttribute()
D. element.dropAttribute()

32 How do you replace one child node with another?

A. parentNode.changeChild(new, old)
B. parentNode.replaceChild(new, old)
C. parentNode.swapChild(new, old)
D. parentNode.updateChild(new, old)

33 Which event is triggered when the user moves the mouse over an element?

A. onmouseenter
B. onmouseover
C. onhover
D. Both A and B

34 What is 'event bubbling'?

A. Events firing from the target element up to the root
B. Events firing from the root down to the target
C. Events firing only on the specific element
D. Events canceling each other out

35 Which method stops the propagation of an event in the bubbling or capturing phase?

A. event.stop()
B. event.pause()
C. event.stopPropagation()
D. event.prevent()

36 How do you change the font size of an element to 20px using JavaScript?

A. element.style.fontsize = '20px'
B. element.style.fontSize = '20px'
C. element.style.font-size = '20px'
D. element.style.textSize = '20px'

37 What property holds the title of the document defined in the <title> tag?

A. document.header
B. document.name
C. document.title
D. document.meta

38 If 'document.getElementById' does not find an element, what does it return?

A. undefined
B. null
C. false
D. An empty array

39 Which collection returns all <img> elements in the document?

A. document.pictures
B. document.imgs
C. document.images
D. document.graphics

40 What is the purpose of 'document.forms'?

A. Creates a new form
B. Submits a form
C. Returns a collection of all forms in the document
D. Validates a form

41 Which of the following is NOT a valid node type?

A. Element Node
B. Text Node
C. Attribute Node
D. Data Node

42 Which method allows you to insert a new node before an existing node?

A. parentNode.insertBefore(newNode, existingNode)
B. parentNode.addBefore(newNode, existingNode)
C. parentNode.prepend(newNode)
D. parentNode.insert(newNode)

43 To toggle a class 'active' on an element, which syntax is correct?

A. element.className.toggle('active')
B. element.classList.toggle('active')
C. element.style.toggle('active')
D. element.toggle('active')

44 What does the 'event.target' property refer to?

A. The element on which the event listener was attached
B. The element that triggered the event
C. The root document
D. The type of event

45 Which event triggers when a user types a key in an input field?

A. onclick
B. onmouseover
C. onkeydown
D. onsubmit

46 How do you access the first child node of an element?

A. element.child(0)
B. element.firstChild
C. element.firstNode
D. element.childNodes[1]

47 Which method can be used to determine if an element has a specific attribute?

A. element.hasAttribute(name)
B. element.containsAttribute(name)
C. element.isAttribute(name)
D. element.checkAttribute(name)

48 What is the third argument in 'addEventListener' used for?

A. The event type
B. The callback function
C. Boolean for useCapture (bubbling/capturing)
D. The execution speed

49 Which DOM object allows access to the browser's history?

A. document.history
B. window.history
C. navigator.history
D. location.history

50 How do you remove an event listener previously added with addEventListener?

A. element.deleteEventListener()
B. element.removeEventListener()
C. element.detachEvent()
D. element.stopListening()