jQuery - Click handler and remove elements to assign

Click handler functions are probably one of the most used when working with jQuery. Rarely get there without them.
I want you today to present briefly a few times finer points to do so.

Click an item to add a handler
An element a click handler mitzugeben is probably the easiest.

? View Code JAVASCRIPT
  1
 2
 3
  ) . click ( function ( ) { $ ('# IdDesElements'). Click (function () (
 "Click handler ausgelöst!" ) ; window alert. ("Click triggered handler");
 )); 

Mehrer Click Add a handler element
An element can account more than just a Click handler assigned.
The item is clicked, any handler in turn exported to.

? View Code JAVASCRIPT
  1
 2
 3
 4
 5
 6
 ) . click ( function ( ) { window. alert ( "Click handler 1!" ) ; } ) ; $ ( '#idDesElements' ) . click ( function ( ) { window. alert ( "Click handler 2" ) ; } ) ; $ ('# IdDesElements'). Click (function () (window. Alert ("Click a handler!");)), $ ('# IdDesElements'). Click (function () (window. Alert ("Click handler 2 ');)); 

Click remove handler
Click again to remove handlers a simple enough unbind.

? View Code JAVASCRIPT
  1
  ) . unbind ( 'click' ) ; $ ('# IdDesElements'). Unbind ('click'); 

Click Add handler and also remove
Since we have the wonderful with jQuery so the chaining method for disposal, we can avoid an element of a previously assigned to him all the Click handler and simultaneously add a new one.

? View Code JAVASCRIPT
  1
 2
 3
 ) . unbind ( 'click' ) . click ( function ( ) { window. alert ( "neuer Click handler ausgelöst!" ) ; } ) ; $ ('# IdDesElements'). Unbind ('click'). Click (function () (window. Alert ("Click handler triggered new!");)); 

Click handler and anchor
When you click a link to an anchor handler calls, but not the will of the browser follows the link, after the handler is called false must also simply a return;

? View Code JAVASCRIPT
  1
 2
 3
 4
  ) . click ( function ( ) { $ ('# IdDesElements'). Click (function () (
 "Click handler" ) ; alert window. ("Click handler");
     ; return false;
 ));