最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery slideToggle() callback function - Stack Overflow

programmeradmin3浏览0评论

Here is the jQuery slideToggle function:

$('.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
    });
});

In the callback function I need to access current .class element (the one being clicked on). How can I do that?

Here is the jQuery slideToggle function:

$('.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
    });
});

In the callback function I need to access current .class element (the one being clicked on). How can I do that?

Share Improve this question edited May 29, 2013 at 21:54 Muhammad Omar ElShourbagy 7,0682 gold badges34 silver badges50 bronze badges asked Aug 7, 2009 at 15:26 Richard KnopRichard Knop 83.7k154 gold badges398 silver badges560 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

Take a reference to the element outside of the callback, you can then use this inside the callback function.

$('.class').click(function() {
    var $el = $(this);
    $el.parent().next().slideToggle('slow', function() {
         //use $el here
    });
});
发布评论

评论列表(0)

  1. 暂无评论