JQuery getting the last index of an input field

I have several “sets” of input fields on a page, for example:

<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 am trying to get the largest index (in this case 123) using jquery. Note that each set is in a div, but those divs do not have unique identifiers. However, all sets are included in the div id="allthesets", and the div immediately after id="rightafterthesets". Since the largest index is the last one, I think the div rightafterthesetscan help in getting the last index, if I could figure out a backup method somehow.

+3
source share
2 answers
var largestID = $("#allthesets div:last input:first").attr("name")

div allthesets div, , po-123 ,

+8

, :

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

Source: https://habr.com/ru/post/1719391/


All Articles