Home > Back-end >  Data model-toggle should dismiss only after click close button?
Data model-toggle should dismiss only after click close button?

Time:03-02

<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div >
  <h2>Small Modal</h2>
  <!-- Trigger the modal with a button -->
  <button type="button"  data-toggle="modal" data-target="#myModal">Open Small Modal</button>

  <!-- Modal -->
  <div  id="myModal" role="dialog">
    <div >
      <div >
        <div >
          <button type="button"  data-dismiss="modal">&times;</button>
          <h4 >Modal Header</h4>
        </div>
        <div >
          <p>This is a small modal.</p>
        </div>
        <div >
          <button type="button"  data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>

</body>
</html>

here the data model should dismiss only after click cancel button .its data-dismisses when we click any side in screen .How to make this using Jquery /java script

CodePudding user response:

Add data-backdrop property to your modal

<div  id="myModal" role="dialog" data-backdrop="static>

CodePudding user response:

In jQuery inside your onClick pass the modal id and do the following

    $('#myModal').modal({
    backdrop: 'static',
    keyboard: false
})

Please find the code snippet below:

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false
})
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div >
  <h2>Small Modal</h2>
  <!-- Trigger the modal with a button -->
  <button type="button"  data-toggle="modal" data-target="#myModal">Open Small Modal</button>

  <!-- Modal -->
  <div  id="myModal" role="dialog">
    <div >
      <div >
        <div >
          <button type="button"  data-dismiss="modal">&times;</button>
          <h4 >Modal Header</h4>
        </div>
        <div >
          <p>This is a small modal.</p>
        </div>
        <div >
          <button type="button"  data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>

</body>
</html>

Or have a look at this.

  • Related