ScoobyDont Posted February 12, 2017 Share Posted February 12, 2017 Hi I am creating a site using bootstrap and have a few collapsed panels, the trouble I am having is when the page first loads the down arrow needs pressing twice before it does anything, can this be fixed js $(document).on('click', '.panel-heading span.clickable', function(e){ var $this = $(this); if(!$this.hasClass('panel-collapsed')) { $this.parents('.panel').find('.panel-body').slideUp(); $this.addClass('panel-collapsed'); $this.find('i').removeClass('fa fa-arrow-up').addClass('fa fa-arrow-down'); } else { $this.parents('.panel').find('.panel-body').slideDown(); $this.removeClass('panel-collapsed'); $this.find('i').removeClass('fa fa-arrow-down').addClass('fa fa-arrow-up'); } }) And this is the code for the header <div class="panel-heading"> <span class="pull-right clickable"><i class="fa fa-arrow-down" aria-hidden="true"></i></span> <h4><i class="fa fa-calendar" aria-hidden="true"></i> Important Events </h4> </div> Thanks for any help in advance Quote Link to comment https://forums.phpfreaks.com/topic/303174-collapsed-button-needs-pressing-twice/ Share on other sites More sharing options...
Strider64 Posted February 12, 2017 Share Posted February 12, 2017 I think you're confusing what is clickable and what is not: https://jsfiddle.net/Strider64/db8NB/ While that isn't the same thing it should show you what I'm talking about. $(function () { var myButton1 = $('.myButton1'), // The Button: box1 = $('.box1'), myButton2 = $('.myButton2'), box2 = $('.box2'); myButton1.on('click', function () { $(this).toggleClass('off'); if ($(this).hasClass('off')) { moveRight(); // Animate Box to the Right: } else { moveLeft(); // Move Box back to the Original Position: } }); myButton2.hover(function () { box2.animate({ 'left': '300px' }); $(this).css('background-color', 'orange'); }, function () { box2.animate({ 'left': 0 }); }); function moveLeft() { box1.animate({ 'left': 0 }); } function moveRight() { box1.animate({ 'left': '300px' }); } Quote Link to comment https://forums.phpfreaks.com/topic/303174-collapsed-button-needs-pressing-twice/#findComment-1542669 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.