I have a list of elements on the page that should be hidden in the sequence, but right after the previous element was completely hidden.
I did the following code, where I create a large string by inserting callbacks inside previous callbacks, and then use eval to execute the effects, but despite the code working fine, as expected, I'm absolutely sure that this is not the best way to do this.
var itemsToHide = jQuery(".hide");
var hideItem = function (item, callback) {
jQuery(item).hide(100, callback)
};
var buff = function(){};
for (var i = 0; i < itemsToHide.length; i++) {
buff = "function(){hideItem(itemsToHide[" + i + "], " + buff + ");}";
}
eval("(" + buff + ")()");
Any suggestion on how to accomplish this effect using recursion without an "evil" eval?
source
share