applebeetrootcarrot
applebeetrootcarrot

Reputation: 25

Jquery: Passing a parameter into the function in .click()

function AAA(i){console.log(i);}

$('div').click({i:'clicked'},AAA);

How do I pass a parameter/data into the function when using .click()? the above does not work.

Upvotes: 1

Views: 90

Answers (4)

Agustin Castro
Agustin Castro

Reputation: 459

you try this

$('div').on('click', AA('test'));

Upvotes: 0

Sudharsan S
Sudharsan S

Reputation: 15393

An optional object of data passed to an event method when the current executing handler is bound.

function AAA(event){
     console.log(event.data.i);
}


$('div').click({i:'clicked'},AAA);

Upvotes: 1

adeneo
adeneo

Reputation: 318182

The data passed in is available as event.data inside the event handlers callback function

function AAA(event){
    console.log( event.data.i );
}

$('div').click({i:'clicked'},  AAA);

FIDDLE

Upvotes: 4

Murali Murugesan
Murali Murugesan

Reputation: 22619

$('div').click(function(){
           AAA('clicked');
});

Upvotes: 0

Related Questions