I cant seem to figure out whats going on here... Im kind of half asleep, really trying to get this last thing done before i go to bed lol.
My goal: Click someone, then check if it has the class, if not, then add it, then remove it once the 1 second animation is complete. Right now im getting unexpteced identifier on the 3rd line down. (removeClass)
Note: the slamedown
class is a keyframe
$('#accountloginsignup h1').click(function() {
if ($('#takeonebar').hasClass('slamdown')){
$('#takeonebar')removeClass('slamedown');
} else {
$('#takeonebar').addClass('slamdown');
}
});
jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".
The hasClass() is an inbuilt method in jQuery which check whether the elements with the specified class name exists or not. Syntax: $(selector). hasClass(className);
if-else statement should be in a function or inside constructor at-least. No. If you want conditions, do it in the functions.
.toggleClass() is for this specific purpose
From the doc
Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument.
$('#accountloginsignup h1').click(function() {
$('#takeonebar').toggleClass('slamdown');
});
There is a typo
$('#accountloginsignup h1').click(function() {
if ($('#takeonebar').hasClass('slamdown')){
$('#takeonebar').removeClass('slamdown'); /* missing . before removeClass */
} else {
$('#takeonebar').addClass('slamdown');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With