Richard Knop
Richard Knop

Reputation: 83705

jQuery slideToggle() callback function

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?

Upvotes: 5

Views: 17622

Answers (1)

redsquare
redsquare

Reputation: 78667

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
    });
});

Upvotes: 20

Related Questions