0

I have an issue in changing class for the element collapsed but with my code it is changing class for every element.

$('.panel-heading').click(function(){
    $(this).next('.panel-body').slideToggle('fast');
    $('.panel-handle').toggleClass('glyphicon glyphicon-minus icon-window');
});

How can I change the class only for the respective element?

1
  • 1
    please share the html, you need to find the panel-handle element in relation to the clicked panel-heading element Commented Sep 19, 2013 at 6:47

3 Answers 3

3

Your selector $('.panel-handle') targets all the .panel-handle elements in the page, instead you need to find the .panel-handle related to the clicked .panel-heading element

I assume the .panel-handle element is a child element of the .panel-heading element, then

$('.panel-heading').click(function(){
    $(this).next('.panel-body').slideToggle('fast');
    $(this).find('.panel-handle').toggleClass('glyphicon glyphicon-minus icon-window');
});
Sign up to request clarification or add additional context in comments.

Comments

1

Try this :

 $(this).find('.panel-handle').toggleClass('glyphicon glyphicon-minus icon-window');

1 Comment

Thanks everyone gave the same answer.. +1
0

use find function to get dom element inside your "panel-heading" class

 $(this).find('.panel-handle').toggleClass('glyphicon glyphicon-minus icon-window');

1 Comment

its accurate that's why bro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.