jQuery Event How to - Move event handler after clicking








Question

We would like to know how to move event handler after clicking.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.4.js'></script>
<style type='text/css'>
div {<!--  w  w w. java  2  s  .c o m-->
  border: 1px solid black;
  height: 50px;
  width: 150px;
}

span#arrowPreview {
  display: none;
}
</style>
<script type='text/javascript'>
$(function(){
    $('.block').live("mouseenter", function() {
        var id = $(this).attr('id');
        $('#arrowPreview').show();
    }).live("mouseleave", function() {
        var id = $(this).attr('id');
        $('#arrowPreview').hide();
    }).live("click", function() {
        $('.block').die('mouseleave');
    });
});
</script>
</head>
<body>
  <div id="div1" class="block">
    <span id="arrowPreview">Arrow</span>
  </div>
</body>
</html>

The code above is rendered as follows: