Unit 6 - Practice Quiz

CSE326 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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

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

2 How does the DOM represent an HTML document?

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

3 Which object represents the entry point to the DOM?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

12 Which method removes a child node from the DOM?

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

13 What property returns the parent node of an element?

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

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

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

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

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

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

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

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

A. element.class
B. element.cssClass
C. element.className
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. Saves data to a file
B. Writes a stream of text to the document stream
C. Writes data to a specific element
D. Writes to the browser console

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

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

21 How do you set an attribute on an element?

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

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

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

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

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

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

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

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

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

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

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

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

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

28 Which event fires when an input field loses focus?

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

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

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

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

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

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

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

32 How do you replace one child node with another?

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

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

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

34 What is 'event bubbling'?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. Text Node
B. Attribute Node
C. Data Node
D. Element 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.toggle('active')
B. element.style.toggle('active')
C. element.className.toggle('active')
D. element.classList.toggle('active')

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

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

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

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

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

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

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

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

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

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

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

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

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

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