Bootstrap modal not working after clicking button

I had tried bootstrap modal and its button is not working. Please help out Thank u

My code that is not working:

  <body>
    <div class="quit_modal" tabindex="-1" role="dialog" data-toggle="modal" data-target="quit_model">
  <div class="modal-dialog" id="delete-file-modal" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="btnClose" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-4 ml-2"></div>
                    <button type="button" class="btn btn-secondary"><a id="close" data-dismiss="modal" data-target="#quit_modal">Close</a></button>&nbsp;&nbsp;
                     <button type="button" class="btn btn-danger">Button</button>
            </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script type="text/javascript">

    $("quit_Modal").modal('show');

     $('btnClose').trigger('click');

</script>

 </body>

https://i.sstatic.net/bj16u.png

Upvotes: 0

Views: 2754

Answers (3)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

Your current selectors ( "quit_Modal" and 'btnClose') with no class . or identifier # signs will refer to tags, so the jQuery will search for tags with the name of <quit_Modal> and <btnClose> in your DOM.

You're missing the selectors sign (dot . and #):

$("#quit_Modal").modal('show');
$('.btnClose').trigger('click');

NOTE: The quit_Modal should be an id id="quit_Modal".

jQuery(document).ready(function(e) {
  $("#quit_Modal").modal('show');

  setTimeout(function() {
    $('.btnClose').trigger('click');
  }, 1000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.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" />
<div class="modal fade" id="quit_Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default btnClose" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-danger">Button</button>
      </div>
    </div>
  </div>
</div>

Upvotes: 1

lucky
lucky

Reputation: 318

$("quit_Modal").modal('show');

$('btnClose').trigger('click');

Both are class so first put dot(.) before it...

$(".quit_Modal").modal('show');

$('.btnClose').trigger('click');

Upvotes: 0

Xander
Xander

Reputation: 1011

Your selector is wrong.

Instead of:

$("quit_Modal").modal('show');
$('btnClose').trigger('click');

use this:

$(".quit_Modal").modal('show');
$('.btnClose').trigger('click');

Upvotes: 0

Related Questions