prog rice bowl
prog rice bowl

Reputation: 778

jQuery submit functions

although I have been coding jQuery for quite some time now, I was just wondering, what is the difference between $("#test").submit(); and $("#test).submit(function(e){...}); functions? The example here doesn't seem to be very clear to me... Can anyone give any example to show a great use for both of them?

Upvotes: 0

Views: 158

Answers (1)

Elias Soares
Elias Soares

Reputation: 10254

$("#test").submit()

This will trigger a submit to #test, if this is a .

$("#test").submit(function(e) { } )

This will bind a handler function for submit event at form #test.

You can use 1st to submit a form without user interference, for example.

And you can use 2nd to bind a handler function that do something before form submitting, or event disable form submitting by using e.preventDefault().

Upvotes: 1

Related Questions