Q
What is the purpose of the classList property in JavaScript?

Answer & Solution

Answer: Option A
Solution:
The classList property in JavaScript is used to access and manipulate the CSS classes of an HTML element. This property provides methods like add(), remove(), toggle(), and contains() to manage CSS classes dynamically, allowing for easy addition, removal, or toggling of classes based on application logic or user interactions.
Related Questions on Average

Which JavaScript method allows you to change the text content of an HTML element?

A). innerHTML

B). setAttribute

C). textContent

D). createElement

How can you dynamically change the text content of an HTML element based on user input using JavaScript?

A). Use event listeners like addEventListener to detect input changes and update the element's text content

B). Use inline JavaScript in the HTML element's onclick attribute to update the text content

C). Use the onChange event directly in the HTML element's tag to update the text content

D). Use the inputValue property in JavaScript to directly modify the element's text content

How can you dynamically add a new paragraph element to an HTML document using JavaScript?

A). document.createElement('p') followed by appendChild()

B). document.getElementById('newParagraph').textContent = 'New Paragraph';

C). document.querySelector('p').innerText = 'New Paragraph';

D). document.innerHTML = '<p>New Paragraph</p>';

How can you change the background color of an HTML element using JavaScript?

A). element.style.backgroundColor = 'red';

B). element.background = 'red';

C). element.bgColor = 'red';

D). element.color = 'red';

What does the appendChild() method do in JavaScript?

A). Appends a new child node to an existing element in the DOM

B). Removes a child node from an existing element in the DOM

C). Replaces an existing child node with a new node in the DOM

D). Creates a new parent node for an existing child node in the DOM

Which JavaScript method is used to replace one HTML element with another in the DOM?

A). replaceChild()

B). replaceElement()

C). replaceNode()

D). element.replaceWith()

Which JavaScript property is used to change the source (URL) of an image element?

A). src

B). url

C). href

D). source

How can you dynamically change the CSS style of an HTML element using JavaScript?

A). Use the style property of the element to modify CSS styles

B). Use the setStyle() method to apply CSS styles to the element

C). Use inline CSS within the HTML element's tag to specify styles

D). Use external CSS files and link them to the HTML document

Which JavaScript event is triggered when a user clicks on an HTML element?

A). click

B). hover

C). submit

D). change

Which JavaScript method is commonly used to create a new HTML element dynamically?

A). document.createElement()

B). document.appendElement()

C). document.makeElement()

D). document.createNode()