1

I have some existing code where I want to make some changes. Here it is calling a trigger function

$('table.fields tr:last').find('.options').trigger('click', [$this.data('id')])

and here is the function receiving two params,

$(document).on 'click', 'form .options', (event, time) ->

I have to pass another variable index

What I am trying is something like:

index = 1
$('table.fields tr:last').find('.options').trigger('click', [$this.data('id')], index)

And receiving like:

$(document).on 'click', 'form .options', (event, time, index) ->
  console.log index

but I am getting index undefined in function.

2 Answers 2

1

Pass time params in array while Function call

$('table.fields tr:last').find('.options').trigger('click', [$this.data('id'), index])

Function defination will remain same as you are doing

$(document).on 'click', 'form .options', (event, time, index) ->
  console.log index
0

If you want pass variables you have to use an array, like this

 .trigger( eventType [, extraParameters ] )

 .trigger('click', [$this.data('id'), index])

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.