Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery mouseenter mouse leave

Tags:

jquery

.net

I am having trouble getting the moues enter mouse leave functionality work. I know there is a .hover option I can take, I want to get the mouseenter/mouseleave working before i go up to that.

What i am seeing is, I have chrome opened up and am inspecting the img, it says that the src file is changing but i am not seeing a noticable change. Can someone help please

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="jquery-1.4.3.min.js" type="text/javascript"></script>


</head>
<body>

            <img id="menuHome" src="m_home.gif" />
                <script type="text/javascript">

                    $(document).ready(function() {
                        $("#menuHome").mouseenter(function() {
                            $(this).attr({ src: 'm_home_roll.gif' });
                        });
                        $("#menuHome").mouseleave(function() {
                            $(this).attr({ src: 'm_home.gif' });
                        });
                    });
    </script>

</body>
</html>

1 Answers

I had a similar problem with Chrome I think, I seem to remember using mouseover and mouseout instead. So something like this:

$(document.ready(function() {
    $('#menuHome')
        .mouseover(function() {
            $(this).attr({src: 'm_home_roll.gif'});
        })
        .mouseout(function() {
            $(this).attr({src: 'm_home.gif'});
        });
});

There is also no need to select the element twice (hence the single $('#menuHome') line).

like image 143
Marcus Whybrow Avatar answered Nov 22 '25 02:11

Marcus Whybrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!