3

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 要素 (クリックされている要素) にアクセスする必要があります。どうやってやるの?

4

1 に答える 1

19

コールバックの外で要素への参照を取得すると、これをコールバック関数内で使用できます。

$('.class').click(function() {
    var $el = $(this);
    $(this).parent().next().slideToggle('slow', function() {
         //use $el here
    });
});
于 2009-08-07T15:28:27.247 に答える