3

I have a number of "sets" of input fields on page, like this:

<div id="allthesets">
   <div>
      <input name="po-3" type="text">
      <input name="ba-3" type="text">
   </div>

   <div>
      <input name="po-9" type="text">
      <input name="ba-9" type="text">
   </div>

   <div>
      <input name="po-123" type="text">
      <input name="ba-123" type="text">
   </div>
</div>

<div id="rightafterthesets">
   This is the div that comes right after the sets
</div>

I'm trying to get the greatest index (in this case 123) using jquery. Notice that each set is in a div, but those divs don't have unique ids. However all the sets are included in a div id="allthesets" and the div right after it is id="rightafterthesets". Since the greatest index is the latest, I'm thinking the rightafterthesets div could be helpful in getting the last index, if I could somehow figure out the way to back up.

2 Answers 2

9
var largestID = $("#allthesets div:last input:first").attr("name")

This gets the last div in the allthesets div, then gets the first input inside it and gets it's name, which would be po-123 in the example you provided

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

Comments

0

This should work I think:

$('#allthesets > div:last > input')

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.