Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

887
Views
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());
  });
}); 
about 4 years ago · Santiago Trujillo
3 answers
Answer question

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>

about 4 years ago · Santiago Trujillo Report

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)
    });
}); 
about 4 years ago · Santiago Trujillo Report

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!