Click here to Skip to main content
15,066,928 members
Articles / Web Development / HTML
Posted 11 Mar 2008


38 bookmarked

Slide menu using JQuery

Rate me:
Please Sign up or sign in to vote.
3.67/5 (12 votes)
10 Jul 2008CPOL
JavaScript slide menu with JQuery.


jQuery is a fast, concise, JavaScript library that simplifies how you traverse HTML documents, handle events, perform animations, and add AJAX interactions to your web pages. jQuery is designed to change the way that you write JavaScript.

In this article, I'll build a sliding JavaScript menu using jQuery.

Using the code

First, you must reference the jQuery library which can be downloaded form here. Then, you can make the menu HTML page as in the following code:

<html xmlns="" >
    <title>JQuery Sample Menu</title>
    <link rel="Stylesheet" type="text/css" href="styles/navigation.css" />
    <script type="text/javascript" language="javascript" 
    <script type="text/javascript" language="javascript" 
<h2>This is a sample menu using JQuery</h2>
<h4>Try to click on the clickable items in the menu to see the animation</h4>
<ul class="menu">
    <li>- Parent item with no children</li>
    - Item 1 with children
    <ul >
    <li>Nested item 1</li>
    <li>Nested item 2</li>
    - Item 2 with children
    <ul >
    <li>Nested item 1</li>
    <li>Nested item 2</li>
    <li>Nested item 3</li>
    <li>Nested item 4</li>
    - Item 3 with children
    <li>Nested item 1</li>
    <li>Nested item 2</li>
    <li>Nested item 3</li></ul>

Now, for the JavaScript magic! Just use the following JavaScript piece of code:

$(function() // Register the menu
// Add the click event handler on the list item with sub list
            if (this == {
               // Hide all the children of the other lists
               // Make the animation
                     return false;
            // Change the cusrsor.
           // Hide all the nested lists (on the first tinm only).

Now you can have the sliding effect without so much JavaScript coding.

Menu at start:


Menu in action:


Points of Interest

jQuery is a very useful JavaScript library, you should use it! I'll post about JQuery selectors and other operators soon.

I hope that helped.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ahmed Shokr
Architect INC Technologies
Kuwait Kuwait
+7 years of experience in designing and implementing Microsoft Based Solutions.
+5 years of experience in SharePoint implementations from MCMS 2002 to the latest version.
+3 years of experience as presales and technology advisory.
Strong analytic, design and client facing skills.
Strong record in consultation and presales with associated Gulf business understanding and market analysis.
Worked closely with Microsoft Kuwait & Qatar Offices SSPs, PTAs, PAMs and SAMs.
Extensive experience in BizTalk Server 2009, SSAS, PerformancePoint Services and Excel Services.
Active member in the Virtual Technology Specialist and Customer Immersion Experience programs.
Strong record in team leading and projects supervision.

Comments and Discussions

GeneralMy vote of 1 Pin
Member 164379215-Jun-12 14:45
professionalMember 164379215-Jun-12 14:45 
BugLittle update Pin
Member 241225629-Sep-11 10:56
MemberMember 241225629-Sep-11 10:56 
Generalthnx for information Pin
mohamed antar1-May-08 2:46
Membermohamed antar1-May-08 2:46 
GeneralRe: thnx for information Pin
Ahmed Shokr10-Jul-08 2:51
MemberAhmed Shokr10-Jul-08 2:51 
GeneralRe: thnx for information Pin
saqib ku10-Jul-08 20:33
Membersaqib ku10-Jul-08 20:33 
GeneralAbout JQuery Pin
Ahmed Sadek12-Mar-08 23:37
MemberAhmed Sadek12-Mar-08 23:37 
GeneralRe: About JQuery Pin
Ahmed Shokr13-Mar-08 1:00
MemberAhmed Shokr13-Mar-08 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.