views:

34

answers:

2
+2  Q: 

Show Div on Hover

I have the following javascript (with jQuery)

$(function() {

  $(".btnDesc").click(function() {
    $("#desc").slideToggle("slow");
    $(this).toggleClass("active");
  });

When I change .click(function() to .hover(funtion(), as expected, hovering over the link with class="btnDesc" shows the div instead of clicking it, however, I would like to make it show when you stop hovering over the link, the div stays until you click a hide button. With it how I have it, once you stop hovering over the link, the div slides back up.

+2  A: 

You need to use mouseover instead of hover, which captures the event of the mouse moving over the link but doesn't bind to when the mouse moves off of the link.

Mark E
Thanks so much. (I'll accept this answer once Stack Overflow lets me...)
Christopher
A: 

The hover function in jquery requires two functions within it - the mouseover and mouseout functions... e.g.

    $(".btnDesc").hover(
        function() {
            // code to run when mouse hovers in
            $("#desc").show("slow");
            $(this).toggleClass("active");
        },
        function() {
            // code to run when mouse hovers out
            $("#desc").hide("slow");
            $(this).toggleClass("active");
        }
    );

That will show your desc element when you hover over, and hide it when you hover out. The jquery documentation on this function is pretty good too if you get stuck.

Adam
This isn't accurate, it *can* take two functions, or just one like he has currently. The documentation outlines passing one *or* two functions :) http://api.jquery.com/hover/
Nick Craver