jzhangnu
jzhangnu

Reputation: 51

Modal doesn't work in my code

I tried everything and checked it over and over again. But i still can't find what's wrong with my code.

I think the id of the img and the modal is right. And there is also nothing wrong with the head part....

Could you take a look of my code? I'd really appreciate that.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Just a Portfolio</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link href='https://fonts.googleapis.com/css?family=Luckiest+Guy' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/style.css">
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/jquery-2.1.4.min.js">
    </script>

  </head>

  <body>
      <div class="container">

        <div class="row">
          <div class="col-md-6">
            <img src="img/1.png" alt="heiheihei">
          </div>
          <div class="col-md-6 text-right">
            <h1 class="text-uppercase text-thin title-super">Weikang Zhang</h1>
            <h3>It's Now or Never.</h3>
          </div>
        </div>

        <div class="row">
          <div class="col-md-12">
            <img class="title-logo img-responsive" src="img/2.jpg" alt="stussy guy">
          </div>
        </div>

        <div class="row">
          <div class="col-md-12">
            <h2 class="text-muted">Hello</h2>
          </div>
        </div>

        <div class="row">
          <div class="col-md-4">
            <img class="img-responsive" src="img/a.jpg" data-toggle="modal" data-target="#p1">
          </div>
          <div class="col-md-4">
            <img class="img-responsive" src="img/b.jpg">
          </div>
          <div class="col-md-4">
            <img class="img-responsive" src="img/c.jpg">
          </div>
        </div>

        <div class="row">
          <div class="col-md-4">
            <h3 class="text-center">Man</h3>
          </div>
          <div class="col-md-4">
            <h3 class="text-center">Book</h3>
          </div>
          <div class="col-md-4">
            <h3 class="text-center">Woman</h3>
          </div>
        </div>
      </div>

<!-- Modal -->
<div class="modal fade" id="p1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="myModalLabel">Favorite App Page</h4>
      </div>
      <div class="modal-body">
        <img class="img-responsive" src="images/a.jpeg">
        This was my first project in this class. I learned a lot about HTML and CSS.
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

  </body>
</html>

Upvotes: 3

Views: 206

Answers (3)

Senjuti Mahapatra
Senjuti Mahapatra

Reputation: 2590

Apart from placing the source to jquery before bootstrap.js, you need to show the modal. This can be done by $('#modalId').modal('show') Just put this in your JS:

$(document).ready(function(){

  $('#p1').modal('show');

});

Here is a Working Demo

Upvotes: 1

Scarecrow
Scarecrow

Reputation: 4137

problem is here;

<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/jquery-2.1.4.min.js">

bootstrap is depended on jquery so load jquery before bootstrap.js

it should be

<script type="text/javascript" src="js/jquery-2.1.4.min.js">
<script type="text/javascript" src="js/bootstrap.js">

Upvotes: 2

Sarower Jahan
Sarower Jahan

Reputation: 1495

Include the jquery js before bootstrap js. Then try.

Upvotes: 1

Related Questions