jQuery Event How to - Remove event handler with off()








Question

We would like to know how to remove event handler with off().

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  w w w.  ja  v a 2s .c om-->
    $('#a, #b, #c').click(function() {
        console.log('clicked');
        $('#a, #b, #c').off('click');
    });
});
</script>
</head>
<body>
  <div id="a">Div a</div>
  <div id="b">Div b</div>
  <div id="c">Div c</div>
</body>
</html>

The code above is rendered as follows: