Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6780813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:33:02+00:00 2026-05-26T16:33:02+00:00

I am working on dynamically allowing a user to add or remove table rows

  • 0

I am working on dynamically allowing a user to add or remove table rows which contain form fields.

there are two main issues I am having- which entail being able to use a selector to capture the second element of a table (in hopes of ignoring the header row)

and second working with jQuery and the disabled attribute. When calling it initially I cannot change the attribute there after with a js if statement.

my code is here for review: http://jsfiddle.net/Jcortes/BE5Lr/792/

If anyone could help it’d be appreciated.

$(document).ready(function() {
$('#DelBtn').attr('disabled', 'disabled');
var count = 1;
//*******************************************************************    
$('#AddBtn').click(function() {
    //problem is below, the selector is not returning the other elements. (ex=second)
    $("table tr:first").clone().find("input").each(function() {
        $(this).val('').attr('id', function(_, id) {
            return id + count;
        });
    }).end().appendTo("table");
    count++;
    if (count == 2) {
        $('#DelBtn').attr('disabled', '');
    }        
    if (count == 5) {
        $('#AddBtn').attr('disabled', 'disabled');
    }
}); //end AddBtn Function
//*******************************************************************    
$('#DelBtn').click(function() {
    $("table tr:last").remove();
    count--;
    if (count == 1) {
        $('#DelBtn').attr('disabled', 'disabled');
        $('#AddBtn').attr('disabled', '');
    }
}); //end DelBtn Function
//*******************************************************************    
}); //end DOM Ready
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:33:02+00:00Added an answer on May 26, 2026 at 4:33 pm

    The reason the attr('disabled', '') call fails i because you are using jQuery 1.7. jquery 1.7 now properly differentiates between attributes and properties. Disabled is a property. Use the .prop() method instead.

    $('selector').prop('disabled', 'disabled');
    $('selector').prop('disabled', '');
    

    Ah, I see second problem now. You can use nth-child selector to get second row.

    $('table tr:nth-child(2)').clone();
    

    http://jsfiddle.net/BE5Lr/793/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a form where I need to dynamically add inputs whenever the
Working on an ASP.NET 4.0 project, which uses user controls to dynamically generate a
I am working on a project which creates controls dynamically for a form in
Is there something stopping this working, I'm dynamically adding a row to a table,
I am working on a web-application in which dynamically-created images are used to display
I am dynamically adding an image to a canvas object which was working for
I'm working on a web page where I have a dynamically generated table where
I have a UL and I'm working to dynamically add a new LI to
I'm working on a WordPress site that uses a dynamically generated menu system which
Is there a working example out there that demonstrates how to append additional rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.