JQuery for loop of css class names in slidedown() -


Is it possible for a loop to go through the loop and assign a specific code to different CSS classes?

My CSS classes are defined in the template.css file (there are 100 squares with the same name), then it should clearly look like the code given below, which is not in BitD? <$ {'(outside'. '$') ($ "'(' .in '+ i) .hide (); $ (' out '+ i) .hover (function () {$ ('.in internal' + i, this) .stop (true, true) .SlideDown (200);}, function () {$ ('internal' + i, this) .stop (true, true). slideUp (200);});}); }

and my classes are: outsude1, out of 2, out of 3 ... inner 1, inner 2, inner3 ...

Yes, this is possible, but due to a very common peeph in JavaScript your code will fail: your loop's Each recurrence creates a series of functions, and each of these functions stops at same variable i later, when the functions are executed, they < code> i < / code> will have all the same values ​​for a single shared shared frequency, which will be 100 .

You need to pass a unique example of i for each of its internal functions (/ (function) (/), / This is similar to $ (for document). For varied (var i = 0; i & lt; 100; ++ i) {(function (i) {$ ('internal' + i) .hide (); $ ('.outout' + i) .hor (function () ($. 'Inner' + i, this) .stop (true, true) .Sliddown (200);}, function () {$ ('.' + I, this) .stop (true, true) .slideUp (200);});} (i));}});

Note that I have moved the $ (document). out of for loop ; This is a sudden adaptation, which is not directly related to the solution, but is certainly worthwhile. There is no point in complying with 100 callbacks to $ (document). , which code you when you can only take the entire call in a callback.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -