0

i try to create a shop cart using ajax (add working 100% ) but when i try to remove item(s) i found button not clickable

this is the code of delete :

 $(document).on('click', '.delete', function() {
        var product_id = $(this).attr("id");
        var action = "remove";
        console.log('something'); // show nothing
        $.ajax({
            url: "action.php",
            method: "POST",
            dataType: "json",
            data: {
                product_id: product_id,
                action: action
            },
            success: function(data) {
                $('#order_table').html(data.order_table);
                $('#order_footer').html(data.order_footer);
                $('.badge').text(data.cart_item);
            }
        });

    })

Button code :

<button  class="text-danger delete" id="<?php echo $values["product_id"]; ?>"  >
                    <i data-feather="x"></i>
                  </button>
  • 1
    You're using a delegated event handler, so that's correct. When you say the button is not clickable, what exactly do you mean? Can you edit the question to detail the debugging attempts you've made – Rory McCrossan Jun 28 '21 at 16:19
  • 1
    try to check if the click event is being fired before checking if the ajax is working. add a `console.log('something');` before the ajax call to see if this works – Lelio Faieta Jun 28 '21 at 16:23
  • 1
    Hi, welcome to SO. Please take the time to read the [tour] and [ask]. You've provided *some* code, but might also like to read [mcve]. Your issue could be because your delete button simply doesn't have `class=delete`, or it might have click events off via css. Or it's not even a ` – freedomn-m Jun 28 '21 at 16:24

0 Answers0