removeClass() if it exists
You can use .toggleClass()
$('#btnDiv').toggleClass('rotated');
That adds it if it's missing, and removes it if it's present. There's also .is()
to check for things like that:
if ($('#btnDiv').is('.rotated'))
or more simply:
if ($('#btnDiv').hasClass('rotated'))
Just use .toggleClass()
to acheive that.
Try this
if($('#btnDiv').hasClass('rotated')){
$('#btnDiv').removeClass('rotated')
}else{
$('#btnDiv').addClass('rotated')
}