Challenge: Add a Class
This challenge will test your skills in implementing the query selector method to add a class to an element.
We'll cover the following
Problem statement #
In this challenge, you need to use the querySelector
method to add a class to an element. You have to implement the addClass
function to achieve this.
newClass
and anothernewClass
are given to you in the HTML file. In the test
function check the functionality of your addClass
function by adding:
-
newClass
to the firstp
element -
anothernewClass
to theh2
element withclass
burger
.
The
test
function is executed when theAdd Class
button is clicked; hence, the changes after adding the classes should be reflected in the output.
Carefully study the HTML file before implementing the functions.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.