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

890
Visualizações
How To Enable/Disable a Table Row in jQuery

Is there a pre made function in jQuery wherein when you click a button it will enable a row. Then if you click it again, it will disable the row. I found about toggle() and toggleClass(). But it does work when it calls a function. The thought is somewhat like this but I know the syntax is wrong.

jQuery

function disableRows(){
$("#test1table tbody tr").each(function() {
    $(this).find('input:text').prop('disabled', true);
});

function enableRows(){
$("#test1table tbody tr").each(function() {
    $(this).find('input:text').prop('disabled', false);
});

$(document).ready(function() {
  $('.yearButt').click(function(){
      $(this).toggleClass(enableRows(), disableRows());
  });
}); 
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I think below code help you to understand the requirements:

Ref: Enable Disable Controls in a table row

$(document).on('change', '.chkView', function() {
    $(this).closest('tr').find('.chkEdit, .chkDelete').prop('disabled', !this.checked);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="table_forms">
    <tr>
        <td><input type="checkbox" class="chkView"/>View</td>
        <td><input type="checkbox" class="chkEdit" disabled/>Edit</td>
        <td><input type="checkbox" class="chkDelete" disabled/>Delete</td>
    </tr>
   <tr>
        <td><input type="checkbox" class="chkView"/>View</td>
        <td><input type="checkbox" class="chkEdit" disabled/>Edit</td>
        <td><input type="checkbox" class="chkDelete" disabled/>Delete</td>
    </tr>
</table>

over 4 years ago · Santiago Trujillo Relatório

0

You can simplify your code:

$(document).ready(function() {
    $('.yearButt').click(function(){
        var enabled = parseInt($(this).data('enabled'));
        $("#test1table tbody tr input:text").prop('disabled', enabled );

        $(this).data('enabled', !enabled)
    });
}); 
over 4 years ago · Santiago Trujillo Relatório

0

Use toggle not toggleClass, toggle will call functions alternatively on each click event

$(document).ready(function() {
  $('.yearButt').toggle(
      function() { enableRows(); }, 
      function() { disableRows(); }
    );
  });
});

You can also optimize your enable disable code by removing loops and using proper selectors for desired element

$("#test1table").find("input,button,textarea,select").attr("disabled", "disabled");

or this

over 4 years ago · Santiago Trujillo 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