开发者

jquery getting last input field index

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开发者_C百科 I could somehow figure out the way to back up.


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


This should work I think:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜