Javascript Ajax jQuery Html PHP Example Quiz New MORE

jQuery addClass() method with example

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <meta charset="utf-8">
    <title>How to add class in jQuery</title>
    <style>
        .container {
            width: 100%;
            border: 4px solid green;
            padding: 20px;
            background-color: orange;
        }
    </style>
</head>
<body>
    <div>
        <h3>jQuery Tutorial</h3>
    </div>
    <br>
    <button type="button">Add Class</button>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $("div").addClass("container");
            });
        });
    </script>
</body>
</html>
	
Run it Yourself »