Here I'm using bootstrap model, in that model I have some bootstrap cards but every card have a close button if I hit on the close button the card will hide/removed from the bootstrap model popup when model popup have only one card and if I want close that last card also now this time i want to close model popup also automatically. but i am not able to achieve it. any one can please help on me it.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.modal-body{
height: 70vh;
overflow-y: auto;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div >
<!-- Button to Open the Modal -->
<button type="button" data-toggle="modal" data-target="#myModal">
Open modal
</button>
<!-- The Modal -->
<div id="myModal">
<div >
<div >
<!-- Modal Header -->
<div >
<h4 >Modal Heading</h4>
<button type="button" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div >
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 1</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 2</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 3</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 4</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
</div>
<!-- Modal footer -->
<div >
<button type="button" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.clscurrent').on('click', function() {
$(this).closest('.removeit').remove();
});
});
</script>
</body>
</html>
CodePudding user response:
Try This :
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.modal-body{
height: 70vh;
overflow-y: auto;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div >
<!-- Button to Open the Modal -->
<button type="button" data-toggle="modal" data-target="#myModal">
Open modal
</button>
<!-- The Modal -->
<div id="myModal">
<div >
<div >
<!-- Modal Header -->
<div >
<h4 >Modal Heading</h4>
<button type="button" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div >
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 1</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 2</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 3</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body 4</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
<div >
<div ><span>Title</span></div>
<div >
<p>Card body</p>
</div>
<div >
<button >Done</button>
<button >Skip</button>
</div>
</div>
</div>
<!-- Modal footer -->
<div >
<button type="button" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.clscurrent').on('click', function() {
$(this).closest('.removeit').remove();
if($("#myModal").find('div.card').length==0)
{
$("#myModal").modal('hide');
}
});
});
</script>
</body>
</html>
CodePudding user response:
If your modal length is not available or less than one then you can apply this
$('#modal_name').modal('hide')
using jQuery to hide the modal Hope it will help you.