Suppose I've created the following handler (callback) for a form:
$('form').submit(function (event) {
event.preventDefault();
alert('form submitted');
});
Why does calling $('form').get(0).submit
not call the submit handler? The form just gets directly submitted.
.get(0)
returns the native js DOM element ( Same as$('form')[0]
) and then you are triggering the submit event directly.if you are trying to get the first Element use
.eq(0)
and trigger the submit jQuery style using.submit()
.Summary:
$('selector')[0]
~ returns the native js DOM element.get(0)
~ Same as [0]..eq(0)
~ returns the first element as a jQuery object .More:
$('form.selector').submit(function (e) { });
$('form.selector').submit();
OR$('form.selector').trigger('submit');
$('form').eq(0).submit();
Demo: jsFiddle
I hope its what you need.
Demo jQuery:
Demo HTML: