Also the above jQuery code can be done without using the toggle method of jQuery by handling the click event of the button, as mentioned below :-
$(function () {
$("#btnTest").on("click",
function () {
if(!$("#divTest").hasClass("class1")){
$("#divTest").addClass("class1"); $("#divTest").removeClass("class2");
}else{
$("#divTest").addClass("class2");
$("#divTest").removeClass("class1");
}
});
});
Hope this will also be of your help.