1073 0 0 1
Last Updated : 2025-04-28 23:37:13
Pass current data id from anchor tag href to a button in a bootstrap modal - Example (delete confirmation modal)
Pass current data id from anchor tag href to a button in a bootstrap modal , so when click on anchor tag that has the current data id ... we can pass data id to a bootstrap modal using this jquery script - Example (when clicking on delete a record - pass this record id from this anchor tag href to another button in bootstrap modal)
// SCRIPT FOR DELETE SNIPPET
$(".deleteSnippetClass").click(function(){
// get attribute value of href (for snippet id)
var currentSnippetDelete = $(this).attr("href"); // get current href + snippet id
$("#deletehref").attr("href" , currentSnippetDelete ) ; // this passing new href+id to new anchor tag in bootstrap modal
});
Mohammed Anwar
Another great way is to use data- attribute.
Example would be :
<a href='URL' data-id="15" id="link">Click here</a>
In Jquery to get the id, use the following :
var id= $("#link").attr("data-id");
var id = $("#link").data('id');