JQuery Functions

I am trying to remove a class from an HTML tag along with adding a new one, and also do another magic.

Right now, I'm just having procedure style coding ... that I know there is another way to do this. How to create a function inside another function? I’m not sure what he called, and sometimes when he tried to do it, he never worked, so I went down to the type of procedure style, but I decided that I am staying here, and maybe someone can explain to me how does jQuery work? Right now i like

$(this).removeClass("theClass");
$(this).addClass("theClass");
$(this).slideDown();

I think I can do something like

$(this).removeClass("theClass", function(){
  // other goodness?
});

Thanks to everyone. Sorry if I don't make sense.

+3
source share
3 answers

, - .removeClass jQuery , .addClass , :

$(this).removeClass("classA").addClass("classB").slideDown();

, callback ; , . :

$(this).fadeOut("slow", function() {
    // Callback function - called after fade is done
    alert("fade complete");
});
+5

:

$(this).removeClass("theClass").addClass("theNewClass").slideDown();

.

+2

, . , , . , slideDown , :

var that = this;
$(this).removeClass("theClass").sildeDown(function() {
  $(that).addClass("theClass");
});

It will remove the class from the element, move it down, and after the completion of the slide, add the class again. Using a variable is thatnecessary, because inside the anonymous callback function, the thiskeyword can refer to something other than your DOM element. Hope this helps!

+2
source

Source: https://habr.com/ru/post/1753069/


All Articles