I have a few forms with the IDs comment_addXXX. I want to submit all of these at once, rather than individually submit each form.
i.e. Can I simplify something like:
$('#comment_add1111').submit();
$('#comment_add111122').submit();
$('#comment_add1222111').submit();
$('#comment_add11133331').submit();
Into something like:
$('#comment_add*').submit();
asked Feb 2, 2011 at 12:04
aWebDeveloper
38.7k42 gold badges179 silver badges248 bronze badges
3 Answers 3
Try the starts with selector
$('form[id^=comment_add]').each(function() {
$(this).submit();
});
answered Feb 2, 2011 at 12:09
Petah
46.2k30 gold badges161 silver badges217 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
or example, consider the HTML: Example :
<form id="target" action="destination.html">
<input type="text" value="Hello there" />
<input type="submit" value="Go" />
</form>
<div id="other">
Trigger the handler
</div>
The event handler can be bound to the form:
$('#target').submit(function() {
alert('Handler for .submit() called.');
return false;
});
other the id of a control:
$('#other').click(function() {
$('#target').submit();
});
answered Feb 2, 2011 at 12:07
Harold Sota
7,58613 gold badges60 silver badges85 bronze badges
Comments
Aren't quotation marks necessary, Petah?
$('form[id^="comment_add"]').each(function() {
$(this).submit();
});
Comments
lang-js