enb081
enb081

Reputation: 4051

Jquery - Get current event

I know I can get the event, by passing it as a parameter of the function:

$(".selector").on("click", function(event) {


});

How can I get it if it is not a parameter of the function?

For instance,

$(".selector").on("click", function() {

// var event = ???

});

Upvotes: 5

Views: 7362

Answers (3)

Gohil Rajesh
Gohil Rajesh

Reputation: 111

Simply use below code.

$(".selector").on("click", function(event) {
  console.log(event.type); //output = click
});

Upvotes: 0

MAX
MAX

Reputation: 137

$(".myform .form-control").on("input blur",function(e){

    console.dir(arguments[0].handleObj.type);

});

this code can give current name of event

may that can help you :)

Upvotes: 0

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

Even if the parameter is not declared, it is still passed to the function, so you can write:

$(".selector").on("click", function() {
    var evt = arguments[0];
});

Upvotes: 9

Related Questions