0

I want to trigger mouse hover on a hyperlink once the page has been loaded completely.I don't want to use active and visited for this.(Because of some programming reasons).

I mean to say after page loading the hyperlink should be in the having on hover color.

I am trying this code but not getting any success.

<html>
<head>
    <style type="text/css">
    a:hover {
    color: #00a000;
    }
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

        <script type="text/javascript">
            jQuery(document).ready(function(){                          
                jQuery("#myLink").trigger('mousehover');            
            });
        </script>   
</head>
<body>
<a id="myLink" href="www.google.com">google</a>
</body>
</html>
4

1 回答 1

3

Insetad of trying to trigger a mouseevent when there is none, I would just add a class to it. I assume that you have some CSS that already takes care of this. This is much more cleaner IMO and does not abuse 'mousehover'.

jQuery(document).ready(function(){                          
    jQuery("#myLink").addClass('hover');            
});
于 2013-08-08T07:54:01.507 回答