Find the following input field which is in the next div-jquery

I get the last form element that received the value, now I want to find the identifier of the next input element, which is in the next div ...

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

corresponding html code

  <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 find the id of this element </id> 
+4
source share
1 answer

Assuming you start with the input that you have 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 would probably put them in a blur() event or the like.

+8
source

All Articles