jquery - Toggle icon on collapse events -
I have asked this a few times, but I think there can be no work to do for me, I think That's for some answers or older versions of bootstrap in this forum.
First of all I should tell that I am still learning JS and not good at it, but my position is here. I have an emergency style collapse on which I am trying to change the class when the group is either open or closes, in this way the icon I am using is open from an open icon Switch will be.
This is my markup:
& lt; div class = "panel-group" id = "accordion" & gt; & Lt; div class = "panel-panel-default" & gt; & Lt; div class = "panel-title" & gt; & Lt; H4 square = "panel-title" & gt; & Lt; Data-toggle = "fall" data-parent = "# accordion" href = "# collapseOne" & gt; & Lt; span class = "accordion-up" & gt; & Lt; / Span & gt; Title & lt; / A & gt; & Lt; / H4 & gt; & Lt; / Div & gt; & Lt; Div id = "collapseOne" class = "collapse in panel-fall" & gt; & Lt; Div class = "panel-body" & gt; Content & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; Here's the CSS:
.accordion-up {background: url ("images / accordion-up.png") No-repeatable scrolls 0 RGBA (0, 0, 0, 0); Padding: 5px 20px; } .accordion-down {background: url ("images / accordion-down.png") No-repeat scrolls 0 0 RGBA (0, 0, 0, 0); Padding: 5px 20px; } This is my JS:
$ (document) .ready (function () {$ ('# accordion'). Go "(" adrian-down "). AddClass (" erordan-up ");}); $ ('#ordion'). ('Hidden', function () {$ (". Accordion-up ") removeClass ("Ardi-Up"). addClass ("Ardi-Down");});}); If someone can help me find out how to toggle these changes, then it would be greatly appreciated.
Thank you!
Your callback syntax for Bootstrap 3 is incorrect.
$ (document) .ready (function () {$ ('# accordion'). ('Show.bs.collapse', function () {$ (". Accordion-down "). AddClass (" Ardi-Up ");}) $ ('#Adrian'). ('Hidden.bs.collapse', function () {$ (". Accordion-up ") .removeClass (" Ardi -up "). AddClass (" Ardi-Down ");});}); Here is a simple version combining the functions of a function and toggleing classes: $ (function () {} // Shorthand for the document. $ $ ('# AmpRarian'). ('Shown. BScalls hidden .bss.', Function () {$ ('. Accordion-down, .accordion-up') Toggleclass ('Accordion-down accordion-up');});});
Comments
Post a Comment