Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
why JavaScript Find method not finding the element inside a table

I have go a varabile called checkBox which should find the input tag inside the <td> and an attribute to it. but the find method seems not finding the input tag. does any one knows why.

$("#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>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this:

$("#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);
    }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda