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 first p element

  • anothernewClass to the h2 element with class burger.

The test function is executed when the Add 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 70+ hands-on prep courses.