What is the event namespace for jquery?
Let's look at the following simple code:
$ ("#btn"). On ("click.name1.name2",function() { console.log (1); })
Where name1, Name2 is the namespace of the binding click event, where the namespace is followed by the event name with "." To connect. Namespaces can also be understood here as aliases, where the Click event bound here has two aliases name1 and name2.
How does binding an event with a namespace unbind?
Here are 8 ways to unbind the Click event of a namespace that was previously bound click.name1.name2:
1 $ ("#btn"). Off ("click"); 2 $ ("#btn"). Off (". name1"); 3 $ ("#btn"). Off (". name2"); 4 $ ("#btn"). Off (". Name1.name2"); 5 $ ("#btn"). Off ("click.name1"); 6 $ ("#btn"). Off ("click.name2"); 7 $ ("#btn"). Off ("click.name1.name2"); 8 $ ("#btn"). Off ("click.name2.name1");
9 $ ("#btn"). Off (". name2.name1");
1 will unbind all click events (including any namespaces);
2 Cancels all events (not just the Click event) that include name1 in the binding namespace;
3 Cancels all events (not just the Click event) that include name2 in the binding namespace;
4 Cancels all events (not just the Click event) that include name1 and name2 in the binding namespace;
5 cancels the Click event that includes name1 in the binding namespace;
6 cancels the Click event that includes name2 in the binding namespace;
7, 8 cancels the Click event in the binding namespace that includes name1 and name2 (NAME1 and name2 two namespaces are level, not parent and child relationships);
9 Cancels all events (not just the Click event) that include name1 and name2 in the binding namespace;
Combining these can be found in the namespace of the jquery event similar to the class name of the tag, so it is very good memory. What if you only want to unbind the click event without a namespace? It's actually very simple:
$ ("#btn"). Off ("click!");
Add "!" to the event name when you unbind it So that events with namespaces are not affected.
Ps
jquery can also bind and unbind custom events, and custom events can have namespaces.
On the jquery event namespace