<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1, h2, p").addClass("blue");
$("div").addClass("important");
});
});
</script>
<style>
.important {
font-weight: bold;
font-size: xx-large;
}
.blue {
color: blue;
}
</style>
</head>
<body>
<h1>WorkingCode 1</h1>
<h2>WorkingCode 2</h2>
<p>Thankyou WorkingCode.in</p>
<p>Thankyou again WorkingCode.in</p>
<div>ADD Text</div><br>
<button>Add classes to elements</button>
</body>
</html>
Output:
jQuery addClass() Method
admin Changed status to publish December 26, 2023