You just need to stop the click event from scrolling over the elements of the accordion, then if you click on the element of the child accordion, the event of the child clicking will not close the parent element.
The modification is simple, you need to add the param event to the click handler and use event.stopPropagation (); inside st else with the activation code of the current clicked element.
modified code, please look at the code comments:
;(function ($, window, undefined){ 'use strict'; $.fn.foundationAccordion = function (options) { var $accordion = $('.accordion'); if ($accordion.hasClass('hover') && !Modernizr.touch) { $('.accordion li', this).on({ mouseenter : function () { var p = $(this).parent(), flyout = $(this).children('.content').first(); $('.content', p).not(flyout).hide().parent('li').removeClass('active'); flyout.show(0, function () { flyout.parent('li').addClass('active'); }); } }); } else { //be sure to add the param event in the click function handler $('.accordion li', this).on('click.fndtn', function (event) { var li = $(this), p = $(this).parent(), flyout = $(this).children('.content').first(); if (li.hasClass('active')) { p.find('li').removeClass('active').end().find('.content').hide(); } else { //stop event propagation event.stopPropagation(); $('.content', p).not(flyout).hide().parent('li').removeClass('active'); flyout.show(0, function () { flyout.parent('li').addClass('active'); }); } }); } }; })( jQuery, this );
Mario bellart
source share