The ultimate goal is to use Ajax to delete the listing button, which is asynchronous and can be removed from the UI.
As a preliminary step, we would like to implement a function that can only be deleted on the front side of the jquery.
In addition, as a way to implement this feature, if you click the button, you will need to get the id of each list on the js side, which is a struggle.
I want to create an html data attribute and get an id on the front side, but I can only get the first id of the list when I click it
How can I get each id by clicking on the button on the list that I got from laravel?If you have any advice, please take care of it.
blade file The process is to get 10 $songs from SongTable.I will omit the code for this variable as the main question is from the front desk.
<table class="table table-striped">
<thead>
<tr>
<th>Title </th>
</tr>
</thead>
<tr>
@foreach($songs as$song)
<divid="delete-item">
<td class="align-middle">
<a href="{{route('admin.show', ['id'=>$song->id]}}">
{{ $song->title}}
</a>
</td>
<td class="align-middle">
// Here it is.
<button id="delete-btn" data-id="{{$song->id}}" class="btn btn-danger">delete</button>
</td>
</tr>
</div>
@endforeach
</table>
$(function(){
$('#delete-btn').on("click", function(){
console.log($('#delete-btn') .data())
});
});
How to "add", "delete", "move", and "change" the table lines in JavaScript/jQuery
Using this article as a reference, I was able to delete only the front desk.It seems that you didn't have to specify id(class) individually in the first place.
<button onclick="return confirm('Are you sure you want to delete it?') "class="btn btn-danger removeList" > Delete </button>
$( document ).on('click', '.removeList', function(){
$(this)
.parent()
.parent()
.remove();
});
572 Who developed the "avformat-59.dll" that comes with FFmpeg?
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
571 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.