1

jQuery functions can have argument choices or no arguments.

The jQuery documentation uses function() { ..some code.. } in their examples, but usually don't use eventData.

What is the distinction between eventData & eventObject in:

.click( [eventData ], handler(eventObject) )

when the syntax can also be:

.click( handler(eventObject) )

Can handler(eventObject) be a user created function like doSomethingHere()?

1
  • 1
    eventData is (optional) data that is passed to the handler when the event is bound. To retrieve it, you use eventObject.data. eventData can be anything you want to pass (and populates eventObject.data), while eventObject is something specific jQuery calls every event handler with: api.jquery.com/category/events/event-object Commented Apr 23, 2014 at 16:31

1 Answer 1

4

DEMO - http://jsfiddle.net/P7XU8/

Here [eventData] are the optional parameter(s) you want to send to the handler.

$(".selector").click({param1: "MOM", param2: "DAD"}, myFunc);

function myFunc(event){
    alert(event.data.param1);
    alert(event.data.param2);
}

Or

http://jsfiddle.net/P7XU8/1/

$(".selector").click({
    param1: "MOM",
    param2: "DAD"
}, function (event) {
    alert(event.data.param1);
    alert(event.data.param2);
});

Documentataion & example here https://api.jquery.com/event.data/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.