jQuery Style How to - Assign element's hover css properties to some other element








Question

We would like to know how to assign element's hover css properties to some other element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   w w w. j  av a2 s  .  co  m-->
    $(function() {
       $('.abcClass').hover( function(){
          $(this).css('color', 'red');
       },
       function(){
          $(this).css('color', 'green');
       });
    });
});
</script>
</head>
<body>
  <a href="#" class="abcClass">Link To Something</a>
</body>
</html>

The code above is rendered as follows: