Tengo una variable llamada checkBox que debería encontrar la etiqueta de entrada dentro de <td> y un atributo para ella. pero el método de búsqueda parece no encontrar la etiqueta de entrada. ¿Alguien sabe por qué?
$("#table-products tbody tr td").on('click', function () { var checkBox = $(this).find("input"); if ($(checkBox).is(':checked')) { checkBox.prop("checked", false); } else { checkBox.prop("checked",true); } }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="table-responsive"> <table class="table table-hover table-bordered" id="table-products"> <thead> <tr> <th>Product Name</th> <th>Product Categorey</th> <th>Product Price</th> <th>Product Color</th> <th></th> </tr> </thead> <tbody> <tr> <td>Iphone 4</td> <td>Mobiles</td> <td>450</td> <td>Red</td> <td><input type="checkbox" class="product-checkbox" /></td> </tr> </tbody> </table> </div> </div> </div> </div>Prueba esto:
$("#table-products tbody tr td").on('click', function () { var checkBox = $(this).parents('tr').find("input"); if ($(checkBox).is(':checked')) { checkBox.prop("checked", false); } else { checkBox.prop("checked", true); } });