[0].click or just .click?

click, javascript

Solution

Assuming element is a jQuery object, `element.click()` triggers a click event on a set of HTML elements that the `element` consists of. It's the same as calling `element.trigger("click")`

`element[0].click()` is invoking the click method on a DOM node (not jQuery object) that is the first in the set that `element` consists of.

See http://api.jquery.com/click/ (first case)

and https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.click (second case)

for further reference.

Problem

I would like to know why some people use ``` element.click(); ``` and others use ``` element[0].click(); ``` What's the difference? Thanks

Original source