tags:

views:

91

answers:

3

Hi I have the code below, once the first (only) item in the menu is hovered over, the subtext should appear. I have used 'this' as I thought it should find the class with the "li" and then slideDown. This doesnt seem to work, although 'this' works for when you remove the hover, as it slides up (top part not the subtext).

<body>
<script type="text/javascript">
$(document).ready(function() 
 {


    $('li').hover(function() 
        {

            $(this).stop(true, true).slideDown();                   
        $(this).slideDown("slow");                  
        },

        function ()
        {

         $(this).slideUp("fast");

    }

        );    




}); 
</script> 

    <ul>  
       <li class="hover">  
            <p><a href="#">Hover</a></p>  
            <p class="subtext">Show More</p>  
        </li>  
    </ul>  

Any advice?

Thanks

added css:

ul
{  
     margin:0;  
     padding:0;  
}  

li
{  
     width:100px;  
     height:50px;  
     float:left;  
     color:191919;  
     text-align:center;  
     overflow:hidden;  
}  

a
{  
     color:FFF;  
     text-decoration:none;  
}  

p
{  
     padding:0px 5px;  
}  

.subtext
{  
         padding-top:15px; 
         background-color: #6AA63B; 
}  


.hover
{
    background-color: #6AA63B;
}  
+2  A: 

I thin this is what you're after:

$('li').hover(function() {
  $(this).children('.subtext').stop(true, true).slideToggle();           
}); 

If you want to hide/show the class="subtext" element, you need to find it within the <li> you're hovering over. This does that, and will slide down on hover, up on mouse out. In this example, this refers to the li DOM element, and $(this) refers to the li jQuery object.

Nick Craver
Thanks will try
Elliott
@Elliott - I you want it hidden initially, change it's CSS to this: `.subtext { padding-top:15px; background-color: #6AA63B; display: none; }`
Nick Craver
Its not shown on page load anyway without the display none?
Elliott
Elliott - What behavior do you want? shown initially, hidden, show, then hidden on hover?....can you describe a bit what should be hidden/shown initially, then what should happen? jQuery can do whatever you want, I'm just not sure exactly what you're after.
Nick Craver
I think I have sorted it, removed "overflow: hidden;" from my css seems to fix it
Elliott
+2  A: 

When you use this you are referencing the element that the event was bound to. In this case the LI element. You want to hide and show the P element only. Like this.

HTML

<ul>  
   <li class="hover">  
        <p><a href="#">Hover</a></p>  
        <p class="subtext" style="display: none;">Show More</p>  
    </li>  
</ul>   

jQuery

$(document).ready(function() {
    $('li').hover(function() {
        $(this).children("p.subtext").slideDown("slow");
    },
    function() {
        $(this).children("p.subtext").slideUp("fast");
    });
}); 
Dustin Laine
Thanks but it still doesnt seem to work, I have added css incase anything wrong in that.
Elliott
Check my update
Dustin Laine
Still no luck, thanks again
Elliott
Maybe I am confused on what you are trying to do. What I posted, will show the list item and the "Hover" text. When you hover over it slides down the "Show More" text and when you unhover it slides up that text.
Dustin Laine
Yes thats what it should do, I think I messed up some where in my code
Elliott
Thanks got it :)
Elliott
A: 

firstly you should put the order

 jQuery.noConflict();

then change $ with JQuery example:

<script>
     jQuery.noConflict();

     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('somei

d').hide();

good links at this topic: http://docs.jquery.com/Using_jQuery_with_Other_Libraries http://api.jquery.com/jQuery.noConflict/ with my best wishes

Changing libraries to do something jQuery does fine is not a good solution...
Nick Craver