0

I have a button that responds to javascript function as:

<button type="button"  id="sa-warning">Click me</button>

 <script>
document.getElementById("sa-warning").addEventListener("click",function()
   {
       Swal.fire
       ({
           title:"Are you sure?",
           text:"This will inactivate the advertiser!",
           icon:"warning",showCancelButton:!0,
           confirmButtonColor:"#2ab57d",
           cancelButtonColor:"#fd625e",
           confirmButtonText:"Yes, delete it!"
       })
           .then(function(e){e.value&&Swal.fire("Deleted!","Your file has been deleted.","success")
   })})

 </script>

It works perfectly, when I click the button it opens a modal, etc. But now I need to create that button using jQuery as:

  $(this).find(".btn-group")
  .append("<button type='button' class='btn btn-light btn-sm dropdown-toggle' data-bs-toggle='dropdown' aria-expanded='false'>Actions<i class='mdi mdi-chevron-down'></i></button>
<ul class='dropdown-menu dropdown-menu-end'>
<li>
<button id='sa-warning' class='dropdown-item text-danger' type='button'>Mark Inactive</button>
</li>
</ul>");

As you can see I have exactly the same button, but it is inside a dropdown button and when I click it just does not respond, what am I doing wrong?

Demian
  • 65
  • 5
  • The top content on the linked duplicate uses jQuery, but you can scroll down to additional answers which do not. – David Oct 27 '22 at 19:32

0 Answers0