开发者

find the next input field which is in next div-jquery

开发者 https://www.devze.com 2023-04-08 15:03 出处:网络
I am getting the last element of the form which has got value, now i want to find theid of next input element which is in next div...

I am getting the last element of the form which has got value, now i want to find the id of next input element which is in next div...

 var elem1 =$(':text[name^=distanceSlab][value!=""]').last(); 
 var nextElemId = // find the id of next input element which is in next div

the corresponding html code is

 <div id ="divid4">
  <input type="text"  id ="slab4" value ="1"/> // this is the last elemnt which has value
 </div>

 <div id ="div1d5">
      <input type="text"  id ="slab5" value =""/> // need to 开发者_JS百科find the id of this element
 </id>


Assuming that you're starting from the input that you've already identified, then:

$(this).closest('div').next('div').find('input:text').attr('id');

JS Fiddle.

Or:

var thisIndex = $(this).index('input:text');

var next = thisIndex + 1;

var nextElemId = $('input:text').eq(next).attr('id');

JS Fiddle.

I'd probably put those into a blur(), or similar, event.

0

精彩评论

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