if using the following code:
$("#element").on('click', function(){
alert("clicked!");
});
$("#element").on('click', function(){
alert("clicked!");
});
it is well known that the click event will fire twice. because it was bound with the method on() and no unbinding with off() followed.
Now my question is
why on this page the click event method is registered only once no matter how many times you click the binding button??
<script>
function flash() {
$( "div" ).show().fadeOut( "slow" );
}
$( "#bind" ).click(function() {
$( "body" )
.on( "click", "#theone", flash )
.find( "#theone" )
.text( "Can Click!" );
});
$( "#unbind" ).click(function() {
$( "body" )
.off( "click", "#theone", flash )
.find( "#theone" )
.text( "Does nothing..." );
});
</script>
I thought that is because the on() method was binding to a named function not anonymous function. but I tested it on jsbin here and it failed ?
can any one give me a hint of what am I missing here?