1

Are there any pitfalls/ dangers to altering jquery's event object?

For example:

$('#myselector').trigger({type: 'click', myvariable: 'mycontent' })

The additional attribute 'myvariable' gets stored in the event object and I'm able to use it when handling the click event. However, this isn't explicitly outlined in the documentation anywhere - is this considered bad practice?

1
  • What are you trying to accomplish? Commented Mar 6, 2012 at 17:50

2 Answers 2

1

This is perfectly fine, and actually it is in the documentation http://api.jquery.com/trigger/ Notice the bit about 'extraParameters'

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

Comments

1

Trigger already allows for extra parameters to be passed to the event handler:

.trigger( eventType [, extraParameters] )


eventType A string containing a JavaScript event type, such as click or submit.

extraParameters Additional parameters to pass along to the event handler.

http://api.jquery.com/trigger/

So, you can do what you already have, or:

$('#myselector').trigger('click', { myvariable: 'mycontent' });

or:

$('#myselector').trigger('click', 'mycontent');

depending on how you want to handle the data.

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.