jQuery slideToggle() callback function
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);
$(this).parent().next().slideToggle('slow', function() {
//use $el here
});
});
Richard Knop
I'm a software engineer mostly working on backend from 2011. I have used various languages but has been mostly been writing Go code since 2014. In addition, I have been involved in lot of infra work and have experience with various public cloud platforms, Kubernetes, Terraform etc. For databases I have used lot of Postgres and MySQL but also Redis and other key value or document databases. Check some of my open source projects: https://github.com/RichardKnop/machinery https://github.com/RichardKnop/go-oauth2-server https://github.com/RichardKnop
Updated on June 26, 2022Comments
-
Richard Knop almost 2 years
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?