Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is .divClicked here?

Tags:

jquery

What is .divClick here ??

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

some one ask me this question and i have no answer for that. is it event type or namespace ?

like image 537
A.T. Avatar asked Dec 11 '22 17:12

A.T.


1 Answers

Events in jQuery can be written like this:

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

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

One advantage of using namespaces is when you need to unbind 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 a namespace:

$(el).unbind('.divClick');
like image 116
Ja͢ck Avatar answered Dec 30 '22 22:12

Ja͢ck