I'm trying to remove a class from a HTML tag along with adding a new one and also doing some other magic.
Right now I just have a procedure style coding going on... which I know there's another way of doing it. Like creating a function within another function? I'm not sure what it's called and sometimes when trying to do it, it never worked so I went down procedure style type but I figured I post on here and maybe someone can explain to me on how jQuery works? Right now I have like
$(this).removeClass("theClass");
$(this).addClass("theClass");
$(this).slideDown();
I think I can do something like
$(this).removeClass("theClass", function(){
// other goodness?
});
Thanks everyone. Sorry if i don't make sense.
I think what you're looking for is call chaining - since .removeClass returns a jQuery object itself, you can call .addClass directly on the returned object, like so:
$(this).removeClass("classA").addClass("classB").slideDown();
Some animations also take functions called callbacks as arguments; these functions specify actions to take after the animation is complete. For example:
$(this).fadeOut("slow", function() {
// Callback function - called after fade is done
alert("fade complete");
});
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