jQuery slideToggle()回调函数

时间:2009-08-07 15:26:51

标签: javascript jquery callback slidetoggle

这是jQuery slideToggle函数:

$('.class').click(function() {
    $(this).parent().next().slideToggle('slow', function() {
        // how can I access $('.class') that was clicked on
        // $(this) returns the $(this).parent().next() which is the element
        // that is currently being toggled/slided
    });
});

在回调函数中,我需要访问当前的.class元素(被点击的元素)。我怎么能这样做?

1 个答案:

答案 0 :(得分:16)

引用回调之外的元素,然后可以在回调函数中使用它。

$('.class').click(function() {
    var $el = $(this);
    $(this).parent().next().slideToggle('slow', function() {
         //use $el here
    });
});
相关问题