1

Hi there i would like to use slideToggle for a drop down the matter i struck ed there was am trying to toggle swap a anchor element's class in the parent div while Slidedown .foo class and while slideup .eee class should apply and a likely demo for this question is here

$(".select_type").click(function(){
 var id=$(this).attr('id');
 $("#"+id+"_drop").slideToggle(function(){
 if($(this).is(':visible')){  $("#"+id+" a").addClass("foo"); }
 })
 }) 

Here the demo..

help me out.

Vivek Vikranth
  • 3,265
  • 2
  • 21
  • 34

1 Answers1

1

Try this:-

Demo

$(".select_type").click(function () {
    var id = $(this).attr('id');
    $("#" + id + "_drop").slideToggle(function () {
       $("#" + id + " a").attr({
            'class': function (_, oldVal) {
                return oldVal === "up_arr" ? "down_arr" : "up_arr"; //Change the class here, based on prev value.
            }
        });
    })
});
Community
  • 1
  • 1
PSL
  • 123,204
  • 21
  • 253
  • 243