Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
The addEventListener() method attaches an event handler to the specified element.
Question 17 of 50
Which property allows you to read or change the class of an element as a string?
Not quite. Try another option.
Answer: element.className
The className property sets or returns the class name of an element as a string.
Question 18 of 50
Which property allows you to add or remove CSS classes easily using methods like .add() and .remove()?
Not quite. Try another option.
Answer: element.classList
classList provides methods like add(), remove(), and toggle() to manipulate CSS classes.
Question 19 of 50
What does 'document.write()' do?
Not quite. Try another option.
Answer: Writes a stream of text to the document stream
document.write() writes a string of text to a document stream opened by document.open(). Using it after page load overwrites the entire document.
Question 20 of 50
Which attribute is used to access the attribute value of an HTML element?
Not quite. Try another option.
Answer: element.getAttribute(name)
getAttribute() returns the value of a specified attribute on the element.
Question 21 of 50
How do you set an attribute on an element?
Not quite. Try another option.
Answer: element.setAttribute(name, value)
setAttribute() adds the specified attribute to an element, and gives it the specified value.
Question 22 of 50
Which event triggers when a web page has finished loading?
Not quite. Try another option.
Answer: onload
The onload event occurs when an object (like the body/page) has been completely loaded.
Question 23 of 50
Which property provides the full URL of the current HTML document?
Not quite. Try another option.
Answer: document.URL
document.URL returns a string containing the URL of the current document.
Question 24 of 50
What is the return type of 'document.querySelectorAll'?
Not quite. Try another option.
Answer: NodeList
querySelectorAll returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors.
Question 25 of 50
How do you prevent the default behavior of an event (like a form submission)?
Not quite. Try another option.
Answer: event.preventDefault()
The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur.
Question 26 of 50
Which DOM property is used to hide an element using CSS?
Not quite. Try another option.
Answer: Both A and B
Setting display to 'none' removes it from layout. Setting visibility to 'hidden' hides it but keeps space. Both are valid ways to hide elements via DOM CSS.
Question 27 of 50
What is the root element of the document.documentElement property?
Not quite. Try another option.
Answer: <html>
document.documentElement returns the Element that is the root element of the document (for HTML documents, this is the <html> element).
Question 28 of 50
Which event fires when an input field loses focus?
Not quite. Try another option.
Answer: onblur
The onblur event occurs when an object loses focus.
Question 29 of 50
How can you access the text content of a node and all its descendants?
Not quite. Try another option.
Answer: node.textContent
textContent returns the text content of the specified node and all its descendants.
Question 30 of 50
What does the 'this' keyword refer to inside an event handler function defined in HTML?
Not quite. Try another option.
Answer: The element that received the event
In an HTML event handler, 'this' refers to the HTML element that received the event.
Question 31 of 50
Which method is used to remove an attribute from an element?
Not quite. Try another option.
Answer: element.removeAttribute()
removeAttribute() removes the specified attribute from an element.
Question 32 of 50
How do you replace one child node with another?
Not quite. Try another option.
Answer: parentNode.replaceChild(new, old)
replaceChild() replaces a child node with a new node.
Question 33 of 50
Which event is triggered when the user moves the mouse over an element?
Not quite. Try another option.
Answer: Both A and B
Both onmouseover and onmouseenter trigger when the mouse moves over an element (though bubbling behavior differs).
Question 34 of 50
What is 'event bubbling'?
Not quite. Try another option.
Answer: Events firing from the target element up to the root
Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors.
Question 35 of 50
Which method stops the propagation of an event in the bubbling or capturing phase?
Not quite. Try another option.
Answer: event.stopPropagation()
stopPropagation() prevents further propagation of the current event in the capturing and bubbling phases.
Question 36 of 50
How do you change the font size of an element to 20px using JavaScript?
Not quite. Try another option.
Answer: element.style.fontSize = '20px'
The CSS property 'font-size' is written as 'fontSize' in JavaScript (camelCase).
Question 37 of 50
What property holds the title of the document defined in the <title> tag?
Not quite. Try another option.
Answer: document.title
document.title gets or sets the title of the document.
Question 38 of 50
If 'document.getElementById' does not find an element, what does it return?
Not quite. Try another option.
Answer: null
If no element with the specified ID exists, the method returns null.
Question 39 of 50
Which collection returns all <img> elements in the document?
Not quite. Try another option.
Answer: document.images
document.images is a read-only property that returns a collection of all <img> elements in the document.
Question 40 of 50
What is the purpose of 'document.forms'?
Not quite. Try another option.
Answer: Returns a collection of all forms in the document
The forms property returns a collection (an HTMLCollection) of all <form> elements in the document.
Question 41 of 50
Which of the following is NOT a valid node type?
Not quite. Try another option.
Answer: Data Node
Standard DOM node types include Element, Text, Attribute, Comment, and Document. 'Data Node' is not a standard DOM node type.
Question 42 of 50
Which method allows you to insert a new node before an existing node?
Nearly through. Did unit 6 of CSE326 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 6 of CSE326 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.