What is .divClick here?

What is .divClick here ??

$("div#div1").bind("click.divClick",function(){alert("Div Clicked");}) 

someone is asking me this question and I have no answer. is it an event type or namespace?

+4
source share
3 answers

This is the namespace. If the eventType string contains a period character (.), Then the event will be placed in the names. A period character separates an event from its namespace. For example, in a call to .bind ('click.name', handler), clicking on the lines is the type of event, and the name of the line is the namespace. Namespacing allows us to disable or trigger some type events without affecting others. See .unbind () Discussion for more information.

+4
source

Events in jQuery can be written as follows:

 <event-type>[.<event-namespace>] 

In your case, click.divClick is just a click event, except that it is organized in the divClick namespace.

One of the advantages of using namespaces is when you need to disable event listeners:

 $(el).bind('click', function() { alert('click 1'); }; $(el).bind('click.divClick', function() { alert('click 2'); }; $(el).unbind('click.divClick'); 

The last line will unregister only the click 2 event handler without affecting the click 1 event handler.

You can also unregister all events from the namespace:

 $(el).unbind('.divClick'); 
+8
source

This seems to be a custom event.

You can call it like

 $('mySelector').trigger("click.divClick"); 

See the docs: jQuery .bind() Documentation

+1
source

All Articles