javascript - Select element inside same div -


i have 4 input type , 2 div equal name.

<div> <input class="palmetta" type="checkbox" name="palmetta[]" value="1"> palmetta <input class="palmettah" type="text" value="0" name="palmetta[]" ><br> </div>  <div> <input class="palmetta" type="checkbox" name="palmetta[]" value="1"> palmetta <input class="palmettah" type="text" value="0" name="palmetta[]" ><br> </div> 

there way target "palmettah" on first div when check "palmetta" on first div?

i have create this:

$("div .palmetta").change(function() {  if(this.checked) {     $(".palmettah").prop('disabled', true); } else {     $(".palmettah").prop('disabled', false); }  }); 

this script disable palmettah need disable palmettah inside same div of checked input.

select input element based on change event fired element use next() method since it's next checkbox. although if condition not necessary here instead use this.checked second argument in prop() method.

$("div .palmetta").change(function() {     // element `this` refers it's dom object     $(this)        // element next        .next()        // update `disabled` property based on         // `checked` property of checkbox        .prop('disabled', this.checked); }); 

$("div .palmetta").change(function() {    $(this).next().prop('disabled', this.checked);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div>    <input class="palmetta" type="checkbox" name="palmetta[]" value="1">palmetta    <input class="palmettah" type="text" value="0" name="palmetta[]">    <br>  </div>    <div>    <input class="palmetta" type="checkbox" name="palmetta[]" value="1">palmetta    <input class="palmettah" type="text" value="0" name="palmetta[]">    <br>  </div>


Comments