SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    15
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Exclamation JAVASCRIPT AND JQUERY HELP

    below the code and it,s css are:
    CSS>>
    Code CSS:
    body{
    background-color:white;
    }
    a{
    text-decoration:none;
    }
    a{
    color:gray;
    }
    a:hover{
    color:brown;
    text-decoration:underline;
    }
    .wrapper {
     position:relative; height:25px;
    }
    #main {
    	position: relative;
    	margin-left: 30px;
     
    }
     
    #main a {
    	display: block;
    	width: 240px;
    }
    #main ul{
    position:absolute;
    list-style-type:none;
    padding-top: 5px;
    text-align:center;
    }
    #main li{
        float: left;
    	position: relative;
    	padding: 3px 0;
    	text-align: center;
    }
     
     
    #main ul.sub {
    	display: none;
    	position: absolute;
    	top: 20px;
    	left: -10px;
    	padding: 10px;
    	z-index: 90;
    	}
    #main li:hover ul.sub {
    	display: block;
     
     
    	}
    HTML>>

    Code HTML4Strict:
    <html>
    <head>
    <title> 	Msz
    </title>
    <link rel="stylesheet" type="text/css" href="drop.css">
    <script src="jquery-1.2.6.pack.js" type="text/javascript"></script>
    </head>
    <body background="grl.jpg" height="768%" width="1024%">
    <img src="2.PNG" height="20%" width="100%">
    <ul id="main">
    <li><a href="msz.html">HOME</a>
    </li>
    </ul>
    <ul id="main">
    <li><a href="#">Information</a>
    <ul class="sub">
    <li><a href="pages\softwareinformation.html" target="_blank">Software List</a></li>
    </ul>
    </li>
    </ul>
    <ul id="main">
    <li><a href="#">ABOUT</a>
    <ul class="sub">
    <li><a href="pages\author.html" target="_blank">Author</a></li>
    </ul>
    </li>
    </ul>
    <script type="text/javascript">
          $(document).ready(function(){
            $('.sub').hide();
            var mnuTimeout = null;
     
            $('#main').mouseover(function(){
              clearTimeout(mnuTimeout);
              mnuTimeout = setTimeout(function(){$('.sub').slideDown(200);},50);
            });
            $('#main').mouseout(function(){
              clearTimeout(mnuTimeout);
              mnuTimeout = setTimeout(function(){$('sub').slideUp(200);},50);
            });
          });
    	  </script>
    </body>
    </html>

    the problem is that when i mouseover on the home tab all other hiden content,s are shown and, doesnot hide when i mouseout plz check and try to solve it....
    Last edited by TechnoBear; Jan 12, 2013 at 05:04. Reason: Code tags added

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,096
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    The problem is that you have three elements with an id of "main".

    This is invalid markup. Ids should be unique to a page.
    If you want to apply the same css style to multiple elements, use classes.

    The way to solve this, is to give each of these elements the same class, use $('.main') to get a reference to all of them, then iterate over them using each to apply the desired behaviour.

    If you run into any problems, let me know.

    P.S. Please use code tags for your future posts. It makes the code easier to read for anyone who is trying to help you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •