Answers for "Add active class onclick javascript"

1

Add active class onclick javascript

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
            .active {
            padding: 5px;
            background-color: #20BF55;
            color: white;
            }
        </style>
    </head>
    <body>
        <div id="text" onclick="makeActive()">
            Click to make Active
        </div>
        <script>
            function makeActive() {
               var element = document.getElementById("text");
               element.classList.add("active");
               element.innerHTML="This is Active";
            }
        </script>
    </body>
</html>
Posted by: Guest on February-12-2021

Code answers related to "Add active class onclick javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language