I am unable to differentiate between trigger('click') vs trigger('click')[0], is there any difference between them?
Asked
Active
Viewed 54 times
2 Answers
5
trigger('click') calls the trigger method with the 'click' parameter.
trigger('click')[0] calls the trigger method with the 'click' parameter, and accesses the first element of whatever it's returning.
Himanshu Upadhyay
- 6,558
- 1
- 20
- 33
Nepho
- 1,074
- 1
- 11
- 32
0
A lot of methods in jQuery return the original jQuery collection to allow for easier chaining.
For instance
jQuery("body").trigger("click").css("background", "red");
// returns the jQuery collection.
If you use an index to access a jQuery collection, you'll get the corresponding DOM element, in my example, document.body.
Axnyff
- 9,213
- 4
- 33
- 37