Javascript API Examples

Heads up! 

This archived doc is for an old version of UberMenu. 

For the current documentation, please visit the UberMenu 3 Knowledgebase

These are example functions for using the UberMenu API; using such code is considered a customization and is outside the scope of support

Adding Custom Javascript

Open a specific submenu based on an external event

In this example we open the submenu of menu item #15 when clicking on a special button with the id ‘my_special_button’

jQuery(document).ready( function($){
      
    $('#my_special_button').click( function(){
        uberMenu_openMega('#menu-item-15');
    });
      
});

Open the current menu item’s submenu on page load

This function will open the submenu of the current menu item

jQuery( 'document' ).ready( function($){
  var id = $( '#megaMenu ul.megaMenu > li.current-menu-item, #megaMenu ul.megaMenu > li.current-menu-parent, #megaMenu ul.megaMenu > li.current-menu-ancestor' ).first().attr( 'id' );
  if( id ) uberMenu_openMega( '#' + id );
});

Turn a single menu item from a hover to a click trigger

In this example we’ll turn menu item #21 into a click instead of hover menu item.

jQuery( 'document' ).ready( function( $ ){
	var id = '#menu-item-21';
	$( id + ' > a' )
		.hover( function(){
			return false;
		})
		.click( function(e){
			e.preventDefault();
			if( $( this ).parent( 'li' ).hasClass( 'megaHover' ) ){
				uberMenu_close( id );
			}
			else{
				uberMenu_openFlyout( id );
			}			
		});
});

On this page