jquery - Get nearest component from a id begining with -
i have tree column similar one.
<div class="col-md-4 column"> <div class="form-group"> <input type="hidden" name="identitycardlist[0].identitycardid"> <label for="identitycardtype1" class="col-sm-3 control-label">type</label> <div class="col-sm-9"> <select id="identitycardtype1" name="identitycardlist[0].identitycardtype" class="form-control"> </select> </div> </div> <div class="form-group"> <label for="idcardvalue1" class="col-sm-3 control-label">valeur</label> <div class="col-sm-9"> <input type="text" class="form-control" id="idcardvalue1" name="identitycardlist[0].value" placeholder="entrer la valeur"> </div> </div> <div class="form-group"> <label for="expirationdatecard1" class="col-sm-3 control-label">expiration</label> <div class="col-sm-9"> <div class="input-group date" id="expirationdatecardpicker1"> <input type="text" id="expirationdatecard1" name="identitycardlist[0].expiration" class="form-control"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-3 col-sm-9"> <div class="checkbox"> <label><input type="checkbox" name="identitycardlist[0].lodgerown" value="">garde sur eux</label> </div> </div> </div> </div> <div class="col-md-4 column"> ... </div> <div class="col-md-4 column"> ... </div>
i put event on change
with:
select.parent().parent().parent()
i'm @ <div class="col-md-4 column">
level
so tried use closest
, find
without success
$("select[id^='identitycardtype']").on('change', function (e){ var select = $(e.target); var selectedoption = select.find("option:selected"); if(selectedoption.data("card-expiration")==true){ //disabled nearest input expidrationdatecard //var inputexpiration = select.parent().parent().parent().closest(input[id^='expirationdatecard']); var inputexpirationselect.parent().parent().parent().closest($("input[id^='expirationdatecard']")); } });
i never value expected.
try : can use closest()
parent col-md-4 column
div , find expirationdatecard
input make disabled.
$("select[id^='identitycardtype']").on('change', function (e){ var select = $(e.target); var selectedoption = select.find("option:selected"); //disabled nearest input expidrationdatecard $(this).closest('.col-md-4.column').find('div.input-group.date input[id^="expirationdatecard"]').attr('disabled',selectedoption.data("card-expiration")==true); });
Comments
Post a Comment