Home >>jQuery Tutorial >jQuery addClass() Method
jQuery addClass() method in jQuery is used to adds one or more class names to the selected elements and note that this method only adds one or more class names to the class attribute but does not remove existing class attribute.
Syntax:$(selector).addClass(classname,function(index,currentclass))
Parameter | Description |
---|---|
classname | It is a required parameter and is used to add one or more class names |
function(index,currentclass) | It is Optional parameter and is used to returns one or more class names to be added to function
|
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".txt1").addClass("txt2");
});
});
</script>
<style>
.txt2 {
font-size: 150%;
color: green;
}
</style>
</head>
<body>
<h1>Phptpoint</h1>
<p class="txt1">Learn here</p>
<button class="btn1">click me to add </button>
</body>
</html>
Learn here