Close button on modal not working...what am i doing wrong?

10,420

Simple example, if you use bootstrap, make sure to do it the bootstrap way.

Also, make sure the references are correct.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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.7/js/bootstrap.min.js"></script>

#myImg {
  width: 100%;
  height: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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.7/js/bootstrap.min.js"></script>

<button type="button" class="btn" data-toggle="modal" data-target="#myModal">Open Modal</button>

<div id="myModal" class="modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      <!-- Modal Content (The Image) -->
      <img id="myImg" src="https://pbs.twimg.com/media/BU27_rrCYAAckFP.jpg" alt="Trolltunga, Norway">
      <!-- Modal Caption (Image Text) -->
      <div id="caption">Modal Caption (Image Text)</div>
    </div>
  </div>
</div>
Share:
10,420

Related videos on Youtube

Breevie
Author by

Breevie

Updated on June 29, 2022

Comments

  • Breevie
    Breevie almost 2 years

    I've made a modal that makes an image pop up when it's clicked but I can't get the close button to work for some reason. Can someone check my code and see where I went wrong? Or give me some suggestions...thank you!

    <div id = "myModal" class = "modal">
            <div class = "modal-content">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <!-- Modal Content (The Image) -->
                <img class="modal-content" id="mimg">
    
                <!-- Modal Caption (Image Text) -->
                <div id="caption"></div>
            </div>
        </div>
        <img id="myImg" src="http://i0.kym-cdn.com/photos/images/newsfeed/001/023/007/f29.png" alt="Trolltunga, Norway" width="300" height="200">
    
  • Omar
    Omar almost 7 years
    are you use bootstrap.js ? open your inspact and see what are showing in console tab
  • Breevie
    Breevie almost 7 years
    it's just not liking the images I've used other then that nothing
  • Breevie
    Breevie almost 7 years
    jquery.min.js:3 Mixed Content: The page at 'preview.c9users.io/cstephens1911/theartisanemporium/…' was loaded over HTTPS, but requested an insecure image 'i.dailymail.co.uk/i/pix/2017/03/13/13/…'. This content should also be served over HTTPS.
  • Breevie
    Breevie almost 7 years
    trying it now broski
  • Dalin Huang
    Dalin Huang almost 7 years
    @Breevie your image are hosted by a site without HTTPS, it is HTTP which is not safe usually. Try this link https://pbs.twimg.com/media/BU27_rrCYAAckFP.jpg
  • Breevie
    Breevie almost 7 years
    I finally got it working thank you so much!! turns out it was something in my CSS...I'm figuring it out now...bless you

Related