jquery - Get the closest input name after clicking on a link -
i have repeating code :
<div class="input-group"> <input type="text" class="form-control" name="001" value="bla bla bla"> <div class="input-group-btn"> <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">action <span class="caret"></span></button> <ul class="dropdown-menu pull-right"> <li><a href="#" class="img-preview">preview</a></li> <li><a href="#" class="img-change">change</a></li> <li><a href="#" class="img-delete">delete</a></li> </ul> </div> </div>
how clicking on change button, can know input name (i.e. : 001) ?
i tried:
$('.img-change').closest('input').name();
may need this
$(document).on('click','.img-change',function(){ var getname = $(this).closest('.input-group').find('.form-control').attr('name'); alert (getname); });
Comments
Post a Comment