Last active
July 12, 2019 17:40
-
-
Save rhaglennydd/7d2c7d5186f5abe635cb263b518e3be2 to your computer and use it in GitHub Desktop.
Bootstrap 4 Multi-Level Dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Adapted from: https://stackoverflow.com/questions/44467377/bootstrap-4-multilevel-dropdown-inside-navigation | |
*/ | |
'use strict'; | |
( function( $ ) { | |
$( '.dropdown-menu a.dropdown-toggle' ).on( 'click', function() { | |
var $subMenu, | |
$this = $( this ), | |
$ancestors = $this.parents( '.dropdown-menu' ), | |
$parent = $this.parent( '.dropdown' ); | |
if ( !$this.next().hasClass( 'show' ) ) { | |
$ancestors.first().find( '.show' ).removeClass( 'show' ); | |
$parent.removeClass( 'show' ); | |
} | |
$subMenu = $this.next( '.dropdown-menu' ); | |
$subMenu.toggleClass( 'show' ); | |
$parent.toggleClass( 'show' ); | |
$this.parents( 'li.menu-item.dropdown.show' ).on( 'hidden.bs.dropdown', function() { | |
$( this ).removeClass( 'show' ).find( '.dropdown-menu .show' ).removeClass( 'show' ); | |
} ); | |
return false; | |
} ); | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment