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. Digital Ordinance Model
B. Document Object Model
C. Document Oriented Module
D. Data Object Model

2 How does the DOM represent an HTML document?

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

3 Which object represents the entry point to the DOM?

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

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

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

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

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

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

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

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. content
B. innerHTML
C. innerText
D. value

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

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

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

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

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

A. parentNode.add(newNode)
B. parentNode.push(newNode)
C. parentNode.appendChild(newNode)
D. parentNode.insert(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.root
B. element.parentElementNode
C. element.parentNode
D. element.topNode

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

A. onchange
B. onmouseclick
C. onmouseover
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. They are identical.
D. innerHTML is read-only.

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

A. element.on('click', function)
B. element.attachEvent('click', function)
C. element.addEventListener('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.classList
B. element.className
C. element.class
D. element.cssClass

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

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

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

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

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

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

21 How do you set an attribute on an element?

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

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

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

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

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

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

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

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

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

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

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

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. onblur
B. onchange
C. onfocus
D. oninput

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

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

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

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

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

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

32 How do you replace one child node with another?

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

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

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

34 What is 'event bubbling'?

A. Events firing from the root down to the target
B. Events firing only on the specific element
C. Events firing from the target element up to the root
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.prevent()
C. event.stopPropagation()
D. event.pause()

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

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

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

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

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.images
B. document.imgs
C. document.pictures
D. document.graphics

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

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

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

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

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

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

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

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

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

A. The element on which the event listener was attached
B. The root document
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. onclick
C. onkeydown
D. onmouseover

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

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

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

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

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

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

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

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

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

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