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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:22:10+00:00 2026-06-18T03:22:10+00:00

i am unable to remove a row in table using dynamically generated buttons. The

  • 0

i am unable to remove a row in table using dynamically generated buttons.
The main problem is that the “alert()” does not work.
How do i catch the ‘click’ event?

jQuery:

$("#officers-table").on('click', '.remove-officer-button', function(e) {
    var whichtr = $(this).closest("tr");

    alert('worked'); // Alert does not work
    whichtr.remove();      
});

HTML/PHP (updated the code)

<table id="officers-table" class="ui-widget ui-widget-content">
<?php if($num_officers > 0): ?>
    <thead>
      <tr class="ui-widget-header ">
        <th>Name</th>
        <th>Director</th>
        <th>Shareholder</th>
        <th>Secretary</th>
        <th colspan="2">Options</th>
      </tr>
    </thead>
<?php endif; ?>
<tbody>
<?php foreach ($officers as $item): ?>
  <tr>
    <td><?=$item->name?> <?=$item->lastname?></td>
    <td><?=$item->is_director?></td>
    <td><?=$item->is_shareholder?></td>
    <td><?=$item->is_secretary?></td>
    <td>Edit</td>
    <td><button type="button" value="<?=$item->id?>" class="remove-officer-button">Remove</button></td>
  </tr>     
<?php endforeach; ?>
  </tbody>
</table>
  • 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-18T03:22:11+00:00Added an answer on June 18, 2026 at 3:22 am

    Try this (Works in JSFiddle):

    $(".remove-officer-button").on('click', function(e) {
        var whichtr = $(this).closest("tr");
        alert('worked'); // Alert does not work
        whichtr.remove();      
    });
    

    Edit
    As everyone said, your code seems to work fine as is. Check this JSFiddle:
    Original Code: http://jsfiddle.net/mkqU2/1/

    You can use the above code as an alternative, but it sounds like you have some other javascript error causing the script to break.

    Also.. Make sure you code is inside the DOM Ready event. If its not, Nothing happens when you click the button.
    The below jsfiddle replicates your error, the click event don’t fire if not wrapped within the DOM Ready event, or window load event.
    Not Inside DOM Ready: http://jsfiddle.net/mkqU2/2/

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

Sidebar

Related Questions

I am unable to use delegate() in Internet explorer 8. It just does not
I am unable to get the following code to work, using this page for
As weird as it may sound, the code that generated pdf using Prawn gem
Duplicate Unable to remove everything else in a folder except FileA I guess that
I tested: rm \-\-remove-files but I am unable to remove it. How can I
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject
I'm using SQLite & in that i'm using the following query- INSERT INTO Contact(FirstName,
I am unable to remove NDK support from my Android project. I have gone
For some strange reason i am unable to remove the first <tr> with this
My page has this extra padding on the top of page that I'm unable

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.