jquery - Find next sibling of the same element type -
this question has answer here:
- how select next matching element? 2 answers
here form:
<form> <input type="text" name="name" id="name"> <label>phone number *</label> <input type="number" name="phone" id="phone"> <label>email address *</label> <input type="email" name="email" id="email"> <h3>event</h3> <label>event type *</label> <input type="text" name="type" id="type"> <input type="text" name="address" id="address"> <input type="date" name="date" id="date"> </form>
i have variable initialized first input
element:
var cur_input;
i want loop through form elements, assigning next input element cur_input
variable in each iteration.
i have tried:
cur_input = cur_input.next(); //failed because there other elements in between cur_input = cur_input.next('input'); //failed reason.
you can try this
var inputs = $('form input'); // input under form var index = input.index(cur_input); // current index var next_input = inputs.eq(index+1); // next input
Comments
Post a Comment