0

What would the equivalent of

document.forms[0].submit();

...be in jquery format? I know it would look like something similar to:

$("form").submit()

But i'm not sure how to just send a general form without knowing it's id

3 Answers 3

4

Since your javascript code is trying to submit first form in the page, in jQuery you've multiple ways to achieve it, one way is to use .first():

Reduce the set of matched elements to the first in the set.

$("form").first().submit()
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I'm using this in a get request. I dumbed down the function for this purpose. Could you tell me if this would work? $.get(link,function (data){ $(data).("form").first().submit(); } );
Try to use: $(data).find("form").first().submit();
1
$("form").eq(0).submit()

Given a jQuery object that represents a set of DOM elements, the .eq() method constructs a new jQuery object from one element within that set. The supplied index identifies the position of this element in the set.

Comments

0

The first submits the first form on the page.

The jQuery equivalent would be:

$("form:eq(0)").submit();

But if it works in plain JavaScript, you shouldn't change it to jQuery! If it isn't broken, don't "fix" it!

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.