Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

how to create class in html

<!DOCTYPE html>
<html>
  
<head>
    <style>
        .geek {
            background-color: green;
            font-size: 50px;
        }
    </style>
</head>
  
<body>
  
    <button onclick="myClass()">Try it</button>
  
    <div id="gfg">Geeks for Geeks</div>
  
    <script>
        function myClass() {
            var elem = document.getElementById("gfg");
            
            // Adding class to div element
            elem.classList.add("geek"); 
        }
    </script>
  
</body>
  
</html>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #create #class #html
ADD COMMENT
Topic
Name
8+5 =