There are maaaaany jQuery plugins that already do this, but here is a small plugin that I wrapped in 10 minutes:
(function($,window,undefined){ var o; $.fn.amazonLikeMenu = function(data,options){ o = $.extend({},options,$.fn.amazonLikeMenu.defaultOptions); return this.each(function(){ createMenu($(this).addClass(o.classPrefix + '_container'),data); }); }; $.fn.amazonLikeMenu.defaultOptions = { classPrefix : "menu", eventPrefix : "menu" }; function createMenu(container,data,options){ container.data('initial_data',data); var ul = $('<ul />').addClass(o.classPrefix + '_ul').appendTo(container), liTemplate = $('<li />').addClass(o.classPrefix + '_li'), descTemplate = $('<span />').addClass(o.classPrefix + '_desc'), linkTemplate = $('<a href="#"/>').addClass(o.classPrefix + '_link'), hTemplate = $('<h3 />').addClass(o.classPrefix + '_link'); $.each(data,function(i,el){ var li = liTemplate.clone().appendTo(ul); if(el.title && el.link) if(typeof el.link === 'string') linkTemplate .clone() .text(el.title) .attr('href',el.link) .appendTo(li); else { createMenu(li.addClass(o.classPrefix + '_has_submenu').append(hTemplate.clone().text(el.title)),el.link,o); } if(el.desc) descTemplate .clone() .text(el.desc) .appendTo(li); }); }; })(jQuery,window)
Elements of your menu consist of a set of objects (useful if you dynamically generate a menu with data from a service):
[ { title : 'link 1', link : '#page1' }, { title : 'link 2', link : '#page2', desc : 'this is an awesome link' }, { title : 'link 3', link : [ { title : "submenu link1", desc : "sample description", link : "#submenu_link_1" }, { title : "submenu link2", link : "#submenu_link_2" }, { title : "submenu link3", desc : "sample description", link : "#submenu_link_3" } ], desc : 'I have a submenu' }, { title : 'link 3', link : '#page3', desc : 'I dont have a submenu :((' } ];
Here is a demo: http://jsfiddle.net/gion_13/6QXZt/ .
It is customizable, so it can be customized to look exactly the same as on Amazon.
PS: It should be borne in mind that the role of css is greater than jquery / javascript in this case.