0

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?

1 Answer 1

1

$("#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().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.