jQuery Selecting the first child with a specific attribute

javascript, jquery, xhtml

Solution

Try:

$(this).children("input[type='submit']:first").val();

Problem

I have a form in HTML with multiple inputs of type submit: ``` <form id = "myForm1" action="doSomethingImportant/10" class="postLink" method="post"> <input type="hidden" id="antiCSRF" name="antiCSRF" value="12345"></input> <input type="submit" value="clickThisLink"></input> <input type="submit" value="Don'tclickThisLink"></input> </form> ``` What I want to do is select only the first input with type submit while ignoring the others, the snippet of code I currently have is as follows, note it is within a for-each loop that goes through all forms on my page, hence (this) to avoid confusion: ``` var name = $(this).find("input[type='submit']").val(); ``` I'm thinking this already grabs the first input of type submit by default, I'm not sure if that assumption is correct or if there's a more formal way of going about it, thanks.

Original source