Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add or Remove CSS Class from an Element in JavaScript</title> </head> <body> <div id="info">Some important information!</div> <script> // Selecting element var elem = document.getElementById("info"); elem.className = "note"; // Add or replace all classes with note class elem.className += " highlight"; // Add a new class highlight elem.className += " bordered padded"; // Add two new classes bordered and padded elem.className = ""; // Remove all classes </script> </body> </html>