I have a question about a simple jQuery accordion I found.
I'd like to use Font Awesome icons to indicate the active/inactive state with plus and minus icons. In my JSFiddle you see the accordion titles with plus icons. When you click on a title the "fa-plus" class needs to change to "fa-minus".
I already did some tests with add and removeClass, but I couldn't get it working. I'm really a jQuery/javascript noob! Hope you guys can help me out :-).
jQuery('.accordion dt').click(function() {
jQuery('.accordion dt').removeClass('active');
jQuery('.accordion_content').slideUp('normal');
if(jQuery(this).next().is(':hidden') == true) {
jQuery(this).addClass('active');
jQuery(this).next().slideDown('normal');
}
});
jQuery('.accordion_content').hide();
Demo
Demo removes minus sign when other tabs are clicked
This is a good solution but when using the first tab opened it gets a little messy. But you can make this work only using css. I'm using bootstrap accordion and font awesome and i created custom icon with it so when the tab is closed it gets the closed icon and when it is opened it get the other icon. here is the html code:
and down here is the css style:
i used to add extra class .accordion-icon-arrow-circle to accorion title and the .collapsed class is called by bootstrap.js when the accordion title is clicked.
Why not chain your code instead of repeat yourself:
Updated Fiddle
Update:
Your final code should look like this:
Updated Fiddle