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

  • SEARCH
  • Home
  • 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 7756429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:49:18+00:00 2026-06-01T12:49:18+00:00

I have a table with a header and an empty body: <table style=width:50%; class=adminlist>

  • 0

I have a table with a header and an empty body:

<table style="width:50%;" class="adminlist">
<thead>
<tr>
<th style="width:80%;">Number</th>
<th style="width:20%;">Quantity</th>
<th style="width:20%;"></th>
</tr>
</thead>
<tbody id="body_orderproducts">
<tr style="background-color: rgb(170, 170, 170);">                      <td class="kmx_nodata" colspan="3">NO DATA.</td>
</tr>
</tbody>
</table>

Now, I load the data and fill the tbody with an ajax function:

var baseurl = '<?php echo HtmlHelper::getComponentPath(true); ?>';
var urlquery_ajax = '<?php echo RouteHelper::urlQueryWithRawAndToken('order&task=');?>';
var order_id = <?php echo $this->item->id;?>;
var kmx = jQuery.noConflict();
kmx().ready(function() {
/**
* Ajax call to load the products linked to the order
*/
function loadTableProducts() {
    var myProductTableBody = kmx('#body_orderproducts');
    myProductTableBody.empty();
    kmx.ajax({
        type: "POST",
        url: baseurl,
        cache: false,
        data: urlquery_ajax + "getOrderProductsInJsonFormatAjax&order_id=" + order_id,
        success: function(data){
                    data = kmx.parseJSON(data);
                    var myProductTableBody = kmx('#body_orderproducts');
                    populateTable(myProductTableBody, data);
                 },
         failure: function(msg){
                    msg = kmx.trim(msg);
                    alert('Error: ' + msg.responseText);
                  }
    });
}
/**
* Populate the table
*/
function populateTable(myTBodyObj, myData) {
    if (myData.rows.length > 1) {
        kmx.each(myData.rows, function(index,item) {
            myTBodyObj.append('<tr><td>' + item.number + '</td><td align="right">' + item.quantity + '</td><td><img id="delete_product_' + item.id + '" name="delete_product_' + item.id + '" class="kmx_image_delete" alt="<?php echo JText::_( 'Delete this product'); ?>" src="components/com_cmpningbo/assets/images/delete.png" /></td></tr>');
        });
    }
    else {
        myTBodyObj.append('<tr><td colspan="2" class="kmx_nodata"><?php echo JText::_( 'NO DATA.'); ?></td></tr>');
    }
    return;
}}
loadTableProducts();
});

Everything works fine and the result is something like:
Table body loaded successfully

Now, I want to add a code to handle the event on click on the image “delete”:

kmx('img[name^="delete_product_"]').live('click', function() {
        alert('click');
        return false;
    });

Each “delete” image has an id and name like: delete_product_XX, where XX is the ID of the record to delete.
That code doesn’t work when the table body is loaded in ajax but it works when the table body is loaded on the page loading (no ajax).
I already checked about this problem and it seems that there is a problem with live about the images? I don’t know how to solve that? Any idea?

  • 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-01T12:49:20+00:00Added an answer on June 1, 2026 at 12:49 pm

    Since you already have a common class on all the delete buttons, you can just create a delegated event handler like this to handle them all with one event handler:

    kmx("#body_orderproducts").on('click', '.kmx_image_delete', function() {
        // you can examine the other cells in this row to get the desired ID
        // or you can parse it off the end of the image id
        var deleteID = this.id.replace("delete_product_", "");
        // now do whatever you want to do to process the deleteID
    });
    

    To make the delegated event handling work for dynamically created objects, you set the first selector to a static parent object that is not dynamically created (that exists at the time you run the code to installed the event handlers) and you set the second selector to something that matches the dynamically create object.

    FYI, .live() has been deprecated from all versions of jQuery. For jQuery 1.7+, .on() is recommended. For jQuery before 1.7, .delegate() is recommended. This is because both .delegate() and .on() can be much more efficient than .live().

    For versions of jQuery before 1.7, it would be this:

    kmx("#body_orderproducts").delegate('.kmx_image_delete', 'click', function() {
        // you can examine the other cells in this row to get the desired ID
        // or you can parse it off the end of the image id
        var deleteID = this.id.replace("delete_product_", "");
        // now do whatever you want to do to process the deleteID
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a table of mine I have the table header, th which have two
I would like to have a table header that looks like the image shown
I have table with Names such as JS Engineering Services$Web User Setup Header and
I have the following table. The header is at it looks and the content
I am trying to have a table header, in a seperate div stay in
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
When I have a table view with some sections which have their own headers
I have 2 tables in separate <div> 's. One is the header and the
i have table structure with 3 colums (column1, column2, column3) and i want to
I have table with 3 columns A B C. I want to select *

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.