How to get row value from table when delete button is clicked?

I am trying to delete row when delete button is clicked.

<tbody>
  {% for dt in data %}
  <tr>
    <td>
      <i class="fa fa-external-link user-profile-icon"></i>
      <a href="{{dt.url}}" target="_blank">{{dt.url}}</a>
    </td>
    <td>{{dt.modified}}</td>
    <td>
      <button type="button" class="fa fa-trash-o btn btn-danger" data-toggle="modal" data-target="#exampleModal{{forloop.counter}}">Delete</button>
    </td>
    <div class="modal fade bd-example-modal-lg" id="exampleModal{{forloop.counter}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModal{{forloop.counter}}">DELETE</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <p>
              Are you sure you want to delete this row
            </p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
            <button type="submit" class="btn btn-primary">Yes</button>
          </div>
        </div>
      </div>
    </div>
  </tr>
  {% endfor %}
</tbody>


When I click on delete button, modal appear for confirmation and when I click Yes then I have to send the {{dt.url}} for corresponding delete button. I could use the input tag with hidden type and set the input value with {{dt.url}} . I am not able to check which delete button is clicked. Please help.


Add <input type="hidden" name="deletefile" value="" id="deletefileID"> outside your table.

Now set the value of button as {{dt.url}.

<button type="button" value="{{dt.url}" class="fa fa-trash-o btn btn-danger" data-toggle="modal" data-target="#exampleModal{{forloop.counter}}">Delete</button>

This is to use this value to set value of hidden input tag whenever delete button is clicked.


$('.btn-danger').on('click',function(){
       var tmp = this;
       tmp = tmp.value;
       $('#deletefileID').val(tmp);
});