May 9, 2013

Exclamation mark doesn't work in trigger() when using event namespace in jQuery 1.9

User2301368’s Questions:

Here is the code:

$("div").on("click",function(){
       console.log("click");
});
$("div").on("click.plugin", function(){
       console.log("click.plugin");
});
$("button").click(function() {
      $("div").trigger("click!");    
});

and the HTML:

<div>test.</div>
<button >Trigger event according to namespace</button>

When I run the code under jQuery 1.8.3, it works. When I click button, it logs click in the console.

But when I change to jQuery 1.9.1, nothing happens when I press the button. It seems like the exclamation mark doesn’t work anymore in 1.9.1.

I can’t find this change in the 1.9 upgrade guide. Does anybody know why?

Use .$ instead of !

$("button").click(function() {
      $("div").trigger("click.$");    
});

Demo [Credits: Tim B James]

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!