I\'m very much a noob, so I think I\'m overseeing something (probably obvious) with twitter bootstrap modal. What I am trying to do is get a modal to launch only on mobile.
$('#myModal').modal('hide')
should do it
According the documentaion hide / toggle should work. But it don't.
Here is how I did it
$('#modal-id').modal('toggle'); //Hide the modal dialog
$('.modal-backdrop').remove(); //Hide the backdrop
$("body").removeClass( "modal-open" ); //Put scroll back on the Body
Add the class hide to the modal
<!-- Modal Demo -->
<div class="modal hide" id ="myModal" aria-hidden="true" >
Javascript Code
<!-- Use this to hide the modal necessary for loading and closing the modal-->
<script>
$(function(){
$('#closeModal').click(function(){
$('#myModal').modal('hide');
});
});
</script>
<!-- Use this to load the modal necessary for loading and closing the modal-->
<script>
$(function () {
$('#myModal').modal('show');
});
</script>
.modal('hide') manually hides a modal. Use following code to close your bootstrap model
$('#myModal').modal('hide');
Take a look at working codepen here
Or
Try here
$(function () {
$(".custom-close").on('click', function() {
$('#myModal').modal('hide');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<a class="custom-close"> My Custom Close Link </a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->