开发者

jquery - how to add/remove class on slideToggle?

开发者 https://www.devze.com 2023-01-23 09:46 出处:网络
I would like to each time the div expands, to add the class \'selecionado\' once the expansion is finished.

I would like to each time the div expands, to add the class 'selecionado' once the expansion is finished. When the contraction is done (the slideUp part) I would like to remove this class.

Can I have a help here please?

$('#btCategoriaA').click(function()
{
  $('#listaCategoriaA').slideToggle('slow', function() {
   $('#btCategoriaA').addClass('selecionado');开发者_开发技巧
  });
});

Thanks in advance, MEM


You can toggle the class using .toggleClass() based on if the element .is() :visible after the animation, like this:

$('#btCategoriaA').click(function() {
  $('#listaCategoriaA').slideToggle('slow', function() {
    $('#btCategoriaA').toggleClass('selecionado', $(this).is(':visible'));
  });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号