Click here to Skip to main content
Click here to Skip to main content

Tagged as

Creating Menus using jQuery

, 5 Feb 2010
Rate this:
Please Sign up or sign in to vote.
This is an example of how to create simple Menus in HTML using jQuery.

This is an example of how to create simple Menus in HTML using jQuery.

<html>
    <head>    
        <title>Menus</title>
        <script type='text/javascript' src='jquery-1.4.min.js'></script>
        <script type='text/javascript'>
            $(document).ready(function()
            {                   
                $("#divSubMenu1,#divSubMenu2,#divSubMenu3,#divSubMenu4,#divSubMenu5").hide();
                $("#tdMenu1").mouseover(function()
                {                    
                    $("#divSubMenu1").slideDown("slow");
                    $("#divSubMenu2").slideUp("fast");
                    $("#divSubMenu3").slideUp("fast");
                    $("#divSubMenu4").slideUp("fast");
                    $("#divSubMenu5").slideUp("fast");
                });
                $("#tdMenu2").mouseover(function()
                {                    
                    $("#divSubMenu1").slideUp("fast");
                    $("#divSubMenu2").slideDown("slow");
                    $("#divSubMenu3").slideUp("fast");
                    $("#divSubMenu4").slideUp("fast");
                    $("#divSubMenu5").slideUp("fast");
                });
                $("#tdMenu3").mouseover(function()
                {                    
                    $("#divSubMenu1").slideUp("fast");
                    $("#divSubMenu2").slideUp("fast");
                    $("#divSubMenu3").slideDown("slow");
                    $("#divSubMenu4").slideUp("fast");
                    $("#divSubMenu5").slideUp("fast");
                });
                $("#tdMenu4").mouseover(function()
                {                    
                    $("#divSubMenu1").slideUp("fast");
                    $("#divSubMenu2").slideUp("fast");
                    $("#divSubMenu3").slideUp("fast");
                    $("#divSubMenu4").slideDown("slow");
                    $("#divSubMenu5").slideUp("fast");
                });
                $("#tdMenu5").mouseover(function()
                {                 
                    $("#divSubMenu1").slideUp("fast");
                    $("#divSubMenu2").slideUp("fast");
                    $("#divSubMenu3").slideUp("fast");
                    $("#divSubMenu4").slideUp("fast");
                    $("#divSubMenu5").slideDown("slow");
                });        
                
                $("#NoMenu").mouseover(function()
                {                       
                    $("#divSubMenu1,#divSubMenu2,#divSubMenu3,#divSubMenu4,
                    #divSubMenu5").slideUp("fast");
                });
                
                $("body").click(function()
                {                       
                    $("#divSubMenu1,#divSubMenu2,#divSubMenu3,#divSubMenu4,
                    #divSubMenu5").hide();
                });
            });
        </script>
    </head>
    <body>
        <div id="divMenu">
            <table width="100%" id="tblMenu" cellspacing="5">
                <tr style="z-index:10">
                    <td id="tdMenu1" style="width:20%">
                        <img src="Menu1.gif" width="100%" 
                        height="30px" alt="Menu1" />
                    </td>
                    <td id="tdMenu2" style="width:20%">
                        <img src="Menu1.gif" width="100%" 
                        height="30px" alt="Menu1" />
                    </td>
                    <td id="tdMenu3" style="width:20%">
                        <img src="Menu1.gif" width="100%" 
                        height="30px" alt="Menu1" />
                    </td>
                    <td id="tdMenu4" style="width:20%">
                        <img src="Menu1.gif" width="100%" 
                        height="30px" alt="Menu1" />
                    </td>
                    <td id="tdMenu5" style="width:20%">
                        <img src="Menu1.gif" width="100%" 
                        height="30px" alt="Menu1" />
                    </td>
                </tr>
                <tr style="position:absolute; z-index:10">
                    <td style="width:20%;position:relative" id="tdSubMenu1">
                        <div id="divSubMenu1">
                         <table width="100%" style="border-color:Red" 
                         id="tblSubMenu1">
                            <tr>
                                <td name="tdSubMenu1">
                                    <img name="subMenu" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" src="Menu1.gif" 
                                    width="100%" height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                               <td name="tdSubMenu1">
                                    <img name="subMenu" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" src="Menu1.gif" 
                                    width="100%" height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                               <td name="tdSubMenu1">
                                    <img name="subMenu" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" src="Menu1.gif" 
                                    width="100%" height="30px" alt="Menu1" />
                                </td>
                            </tr>
                         </table>          
                        </div>
                    </td>
                    <td style="width:20%;position:relative;" id="tdSubMenu2">
                        <div id="divSubMenu2">
                         <table width="100%" style="border-color:Red" id="tblSubMenu2">
                            <tr>
                                <td name="tdSubMenu2">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu2">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu2">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                         </table>  
                        </div>        
                    </td>
                    <td style="width:20%" id="tdSubMenu3">
                        <div id="divSubMenu3">
                         <table width="100%" style="border-color:Red" id="tblSubMenu3">
                            <tr>
                                <td name="tdSubMenu3">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu3">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu3">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                         </table>      
                        </div>    
                    </td>
                    <td style="width:20%" id="tdSubMenu4">
                        <div id="divSubMenu4">
                         <table width="100%" style="border-color:Red" id="tblSubMenu4">
                            <tr>
                                <td name="tdSubMenu4">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu4">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu4">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                         </table>  
                        </div>        
                    </td>
                    <td style="width:20%" id="tdSubMenu5">
                        <div id="divSubMenu5">
                         <table width="100%" style="border-color:Red" id="tblSubMenu5">
                            <tr>
                                <td name="tdSubMenu5">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                            <tr>
                                <td name="tdSubMenu5">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>                      
                            </tr>
                            <tr>
                                <td name="tdSubMenu5">
                                    <img src="Menu1.gif" onmouseover="this.src='Menu1_mouse.gif'" 
                                    onmouseout="this.src='Menu1.gif'" width="100%" 
                                    height="30px" alt="Menu1" />
                                </td>
                            </tr>
                         </table>      
                        </div>    
                    </td>
                </tr>
            </table>
        </div>
        <div id="NoMenu" style="width:100%;height:100%">
            
        </div>
    </body>
</html>

License

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

Share

About the Author

adi007me
Web Developer Cybage Software
India India
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 bueno PinmemberBYJhony19-Jul-11 18:11 
GeneralReason for my vote of 2 lacks description, code is verbose, ... PinmemberTheyCallMeMrJames27-Jul-10 5:27 
GeneralReason for my vote of 3 . Pinmemberheling02235-Jul-10 15:24 
GeneralIt will be very nice to add some short clarification on what... PinmentorMd. Marufuzzaman2-Jul-10 19:52 
GeneralReason for my vote of 2 more description needed. PinmemberDonsw2-Jul-10 17:16 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 5 Feb 2010
Article Copyright 2010 by adi007me
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid