Pass current data id from anchor tag href to bootstrap model

940 0 0 1

Last Updated : 2024-04-23 16:46:37

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
});

Mahmoud Anwar

Mahmoud Anwar

Back End Developer with a passion for developing innovative web applications that expedite the efficiency and effectiveness of organizational success. Well-versed in technology and writing code to create systems that are reliable and user-friendly. Also has the proven ability to motivate, educate, and collaborate effectively to build web applications and effectively track changes. Confident communicator, strategic thinker, and innovative creator to develop software that is customized to meet a company’s organizational needs, highlight their core competencies, and further their success.

1 Comments

  • Image placeholder

    Mohammed Anwar

    2020-08-17 11:51:16

    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');