As far as my understanding, the myForm is an id for a <form>
and it should be an unique id. So why this code use get(0) which seem the selector returns an array.
That is same as this:
$('#myForm')[0].submit();
The thing to notice is that, jQuery selector gives you a jQuery object and only jQuery methods can be applied on it.
But in your case it seems that you want to trigger the native DOM submit
event and that only can be applied on dom nodes not on jQuery objects. So, .get(0)
returns a DOM node and .submit()
event has been triggered on it. Although that can be simplified in javascript as :
document.querySelector('#myForm').submit();
or
document.getElementById('myForm').submit();
If you get to the .get()
docs:
Description: Retrieve one of the elements matched by the jQuery object. The .get()
method grants access to the DOM nodes underlying each jQuery object. If the value of index is out of bounds — less than the negative number of elements or equal to or greater than the number of elements — it returns undefined.