Reputation: 854
everyone , I have an image inside a table cell when I click on that image a bootstrap 4 Modal is opened , I wanted to add click event to that image using JQuery but it doesn't work , Does adding a bootstrap Modal event to an element disables its Click event ????
this is the HTML code:
<span class="col-lg-3" data-toggle="modal" data-target="#confirmModal">
<img id="myImg" class="img-responsive" src="/Content/uploads/done.png" style="cursor:pointer;" alt="@item.OpportunityID"/>
</span>
And the jquery code for testing is simple :
$("#myImg").click(function () {
alert("Clicked");
});
Upvotes: 3
Views: 2623
Reputation:
It's probably an issue with it being created dynamically. If you hook onto an element that's already on the page then it should work.
Change your click function to:
$('body').on('click', '#myImg', function () {
alert('Clicked');
});
Upvotes: 2
Reputation: 2204
In most cases it does not but what kind of click event are you trying to trigger in addition to the modal popping up? You could try to add a simple console.log("working") to see if the click event is really not fired.
Upvotes: 0