Geraldo Isaaks Geraldo Isaaks - 5 months ago 22
jQuery Question

Store and retrieve chained jquery effects/objects in variable

I want to dynamically change jquery effects by storing the chained objects in a variable and concatenating to selector later, so that i have the latest required effect when it needs to exec.
i store a predifined set of jquery chained effects - fadeOut().end().next().fadeIn() - in the data-effect attr, which can change, so i need to reference back to it via a variable to add the effects to $(contentDiv) selector.
So something like; $(selector)effect, won't work.

var effects = document.getElementById('effect').getAtttribute('data-effect');
$(contentsDiv).effects;

Answer

How about this (updated):

var effect = "fadeOut.end.next.fadeIn";
var $obj = $(contentsDiv);
$.each(effect.split('.'),
    function(key, value) {
        $obj = $obj[value]();
    });