Multi-level navigation indicator with jQuery

One of the popular requests I receive when I develop a website with more than 2 level navigation tier is to add indicators for 3rd level navigation. Using jQuery, this can be achieved easily by utilizing FireBug to examine the markup structure on menu items.
jQuery Code
I wrote example codes for jQuery to look for 2nd level menu items that contain 3rd level menu items, and append html markup that adds the symbol » at the right hand side. The example here should work with websites utilizing jQuery Slide Menu that is commonly used in websites including WordPress themes based websites. Be sure to adjust the code for your website if the following example does not work out of the box.
jQuery for WordPress Websites
Add the following code into functions.php, preferably inside child-theme.
|
|
/* Add 3rd menu navigation indicator jQuery in footer */ function add_menuindicator() { ?> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('.jqueryslidemenu ul li ul li').has('.sub-menu').append('<div class="menu-indicator">»</div>'); }); </script> <?php } add_action('wp_footer', 'add_menuindicator'); |
jQuery for Other Websites
Add the following code anywhere appropriate.
|
|
/* Add 3rd menu navigation indicator jQuery into footer */ <script type="text/javascript"> jQuery(document).ready(function() { jQuery('.jqueryslidemenu ul li ul li').has('.sub-menu').append('<div class="menu-indicator">»</div>'); }); </script> |
CSS Code
Lastly, add the following CSS code into your CSS file and adjust it for your website style so that it’s visible and positioned right.
|
|
.menu-indicator { position: absolute; right: 10px; top: 3px; } |
The Result
Once you add example codes like above, you should be able to see a little indicator next to the 2nd level menu item that contains 3rd level menu like this:

Bonus: CoffeeScript example
I’ve been slowly learning CoffeeScript which makes me happy to code with jQuery. I’ve included CoffeeScript version of the example jQuery code above.
|
|
<script type="text/coffeescript"> jQuery -> jQuery(".jqueryslidemenu ul li ul li").has('.sub-menu').append('<div class="menu-indicator">»</div>') </script> |
If you want to quickly experiment the code on your website, be sure to include the following api in your website header.
|
|
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script> |