1

So I'm just trying to do a simple jquery effect but am having issues with the second part of the .hover function. Here's the code:

<div id="toprightboxes">
<ul>
    <li><div id="login"><img src="img/login.png"/></div></li>
    <li>info</li>
    </ul>
</div>
<script>
    $("#login").hover(
        function () {
            $(this).replaceWith('<div id="login"><img src="img/loginhighlight.png"/></div>');
        },
        function () {
            $(this).replaceWith('<div id="login"><img src="img/loginhighlight.png"/></div>');
        }
    );
</script>

The first part of the hover works and the highlight image shows up but when I move off of the image nothing happens.

2 Answers 2

5

Ehm, its the same IMAGE you replace back...

Secondly why use jQuery for such a hover effect? You can easily do this with a:hover {} and pure CSS.

Sign up to request clarification or add additional context in comments.

1 Comment

Sometimes I amaze myself with my smart typing abilities. Also I had thought that the pseudo class hover had some issues with IE7 but upon exploring more it doesn't look like it so thanks for that also
0

I think you have a typo — your event for mouseleave is the same as the one for mouseenter. Is this what you meant?

<div id="toprightboxes">
<ul>
    <li><div id="login"><img src="img/login.png"/></div></li>
    <li>info</li>
    </ul>
</div>
<script>
    $("#login").hover(
        function () {
        $(this).replaceWith('<div id="login"><img src="img/loginhighlight.png"/></div>');
        },
        function () {
        $(this).replaceWith('<div id="login"><img src="img/login.png"/></div>');
                }
    );
</script>

If all you're doing is changing the image, though, you might want to consider using CSS instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.