Clear element.classList in JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

To clear, you can use remove() in JavaScript.


Following is the code −

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
   .removeClass {
      color: red;
<p id="remove" class="removeClass">Javascript Tutorial</p>
<button onclick="removeClassName()">Remove</button>
   function removeClassName() {
      const element = document.getElementById("remove");

To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.

This will produce the following output −

Now, click the remove button, you will get the following output.


This will produce the following output −

Updated on 27-Oct-2020 10:10:25