Reputation: 1
I have a css selector in which it is toggling the default class display:none and show class display:block.
Is it possible to merge the below in a single query?
$('.abc .def').slideToggle();
$('.abc .def').toggleClass('show');
Upvotes: 0
Views: 88
Reputation: 37701
There's no need to have a custom class just for toggling display because the slideToggle
function is already modifying the display property inline.
If you still want to toggle the class as well, probably the best place is in the callback function, like this:
$('.abc .def').slideToggle(function(){
$(this).toggleClass('show');
})
This will toggle the class once the slide animation is done.
Upvotes: 4