javascript - jQuery remove element not working onClick

798

I have the following code that gets generated in PHP.

      <?php
    foreach ($quote->lineItems as $lineItem) {
      $name = "line_item_" . rand();
      $txtValue = "Supplier: " . $lineItem->supplierName . " Model: " . $lineItem->modelName . " Price: " . $lineItem->price . " Quantity: " . $lineItem->quantity;
      ?>
      <table >
        <tr>
          <td><input type='hidden' name='<?= $name ?> id='<?= $name ?>''
            value='<?= $lineItem->id ?>,<?= $lineItem->supplierId ?>,<?= $lineItem->supplierName ?>
            ,<?= $lineItem->modelId ?>,<?= $lineItem->modelName ?>,<?= $lineItem->price ?>
            ,<?= $lineItem->quantity ?>'/>
            <?= $txtValue ?>
          </td>
          <td>
            <button type='button' onclick="onBtnRemove('<?= $name ?>')" >
              Remove
            </button>
          </td>
        </tr>
      </table>
      <?php
    }
    ?>

The onBtnRemove function looks like this.

        function onBtnRemove(idToRemove) {
            const toRemove = $("#" + idToRemove);
            toRemove.remove();
        }

I cannot figure out why the element does not remove.

enter image description here

People are also looking for solutions to the problem: curl - Url trace in Php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.