Reputation: 69
I have a Modal in my webpage which uses Bootstrap. I've added anchor tags in it to which there are href links. When I am trying to click on that anchor element, it is not clickable. Anchor tag is not working in Modal.
Please help me with this issue.
Please find below code -
<div class="portfolio-modal modal fade" id="editionsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="close-modal" data-dismiss="modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="col-sm-3">
<a href="hingoli.html" data-target="#" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Hingoli</h4>
</div>
<img src="pages/hingoli/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="col-sm-3">
<a href="parbhani.html" class="portfolio-link" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Parbhani</h4>
</div>
<img src="pages/parbhani/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
Upvotes: 1
Views: 12193
Reputation: 11
try this
$("#yourModalID table tbody").on('click','.yourBtnClass', function(){ //do something here })
Upvotes: 1
Reputation: 189
Please try this code!
$('#editionsModal .container a').on('click',function( ev){
var $button=$(ev.target);
ev.preventDefault();
$(this).closest('.modal').on('hidden.bs.modal',function(e){
var $href=$button.attr('href');
window.location.href=$href;
});
});
Upvotes: 0
Reputation: 2119
I was having the same behaviour with Bootstrap 4 and it turns out that .modal-dialog
div has a pointer-events: none;
attribute that disables the links. Setting to pointer-events: all;
fixed it for me.
Upvotes: 7
Reputation: 425
Check it, I used clearfix div. but if I don't want clearfix, then I use
(div class="modal-body col-sm-3"
) because link divs have a float value
but modal-body
doesn't.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#editionsModal">Open Modal</button>
<div class="portfolio-modal modal fade" id="editionsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="close-modal" data-dismiss="modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="col-sm-3">
<a href="hingoli.html" data-target="#" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Hingoli</h4>
</div>
<img src="pages/hingoli/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="col-sm-3">
<a href="parbhani.html" class="portfolio-link" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Parbhani</h4>
</div>
<img src="pages/parbhani/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="clearfix"></div>
<div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
Upvotes: 0