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 9186857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:37:59+00:00 2026-06-17T19:37:59+00:00

I am using jQuery DataTables to construct a table for which one can add

  • 0

I am using jQuery DataTables to construct a table for which one can add and remove rows using the following scripts:

Add Row:

var row_count = 1; 

$(document).ready(function() {
$('#my_table').dataTable();
} );

function fnClickAddRow() {
$('#my_table').dataTable().fnAddData( [
    "<input type=\"text\" name=\"fieldA\"" + row_count + " value=\"\" />",
    "<input type=\"text\" name=\"fieldB\"" + row_count + " value=\"\" />",
    // ...
    ] );
 
row_count++;
}

As shown in this example.

I then add row selection and deletion with another script:

var oTable;

$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
  $("#my_table tbody tr").click( function( e ) {
    if ( $(this).hasClass('row_selected') ) {
        $(this).removeClass('row_selected');
    }
    else {
        oTable.$('tr.row_selected').removeClass('row_selected');
        $(this).addClass('row_selected');
    }
});
 
/* Add a click handler for the delete row */
$('#delete').click( function() {
    var anSelected = fnGetSelected( oTable );
    if ( anSelected.length !== 0 ) {
        oTable.fnDeleteRow( anSelected[0] );
    }
} );
 
/* Init the table */
oTable = $('#my_table').dataTable( );
} );


/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
  return oTableLocal.$('tr.row_selected');
}

The add row function (fnClickAddRow()) works fine as does the delete function on rows that are coded in HTML. However, the rows that are added to the table object are not selectable and therefore not deletable. What do I need to add to my data array to make the added rows selectable?

  • 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-06-17T19:38:00+00:00Added an answer on June 17, 2026 at 7:38 pm

    To solve the class not being applied you should use .on() (or .live() for jQuery <1.7):

    // bind to currently available (and future-added) elements
    $('#my_table').on('click', 'tbody tr', function(e){
      /* select code */
    });
    

    then existing <tr> elements (and those added using fnAddRow) will receive the click binding.

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

Sidebar

Related Questions

I am using the Jquery datatables to build a table. I need a row
I am using jQuery dataTables to add new rows dynamically. I am able to
I'm building a simple search table (eventually using jquery Datatables) for our knowledgebase. I'm
I am using jQuery dataTables version 1.9.2 Table is created with class datatable and
I am using JQuery-DataTables-Editable-1.3 along with DataTables-1.9.4. I am able to add the add_delete_toolbar.
I'm using jQuery DataTables . This is my markup: <div class='wrapper'> <form> <table> <tr>
I am using jQuery datatables to display some data. Each row has an edit
I'm using jQuery datatables plug-in on my HTML Table. I wanted to know how
When adding a row dynamically using jQuery DataTables plugin , what do I do
I am using jQuery DataTables . I want to remove the search bar and

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.