
The addClass() or removeClass() methods are used to add the CSS classes when there is a need to add to our webpage, Basic form and Advanced form…etc. when there is some event listener or to create some kind of effect.
Now, will see how can we add a CSS class or remove a CSS class using jQuery.
Syntax:😀😀
Adding a class:
$('selector').addClass(class_name);
Removing a class:
$('selector').removeClass(class_name);
Example: If Alpha field value equal to true enable the button else disable the button.
$(document).ready(function(){
//Adding class to disable the button
$('#IdoftheButton').addClass('disabled');
// Getting the value of Alpha.
var alpha = $("#alpha").val();
// Check condition alpha equal to true or not.
if(alpha == true)
{
// Remove the class to enable the button
$('#IdoftheButton').removeClass('disabled');
}
else{
// Adding class to disable the button
$('#IdoftheButton').addClass('disabled');
}
});
For more Interesting updates Subscribe our YouTube channel: Click Here to Subscribe