0

I've created a modal but it would not display, it worked on an app I created with React, but with vanilla javascript (on a different project) it won't work.

Link for html, css and javascript code: https://codepen.io/J-Kazama/pen/WNbPoZB

If I change the display of .bg-modal to flex from none the modal does show up, so I assume the problem is with javascript.

David
  • 159
  • 1
  • 14

1 Answers1

1

remove the import from your JS and it works...

(function() {

  document.getElementById('revAddButton').addEventListener('click', function() {
    document.querySelector('.bg-modal').style.display = 'flex'
  });
})()
.btn {
  display: inline-block;
  border: none;
  padding: 6px 12px;
  margin-bottom: 0;
  font-size: 14px;
  font-weight: normal;
  text-align: center;
  cursor: pointer;
  border-radius: 4px;
}

.btn-red {
  text-decoration: none;
  color: #fff;
  background: #ff4742;
  border: 2px solid #ff4742;
  border-radius: 25px;
  margin-right: 7px;
}

.btn-red:hover,
.btn-red:active {
  border: 2px solid #ff4742;
  text-decoration: none;
  color: #ff4742;
  background-color: white;
}

.div1:hover,
.div1:focus {
  color: #555555;
  background: rgba(60, 186, 84, 0.25);
}

.parent {
  width: 100%;
  background-color: #f8f9fb;
  margin-top: 160px;
  height: 500px;
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: center;
  align-content: flex-start;
}

.div1 {
  background-color: rgba(70, 220, 100, 0.55);
  position: relative;
  margin: 5px;
  width: 275px;
  height: 220px;
  border: 0;
  border-radius: 5px;
  font-family: 'Varela Round', sans-serif;
}

 ::-webkit-input-placeholder {
  font-family: 'Varela Round', sans-serif;
}

 ::-webkit-moz-input-placeholder {
  font-family: 'Varela Round', sans-serif;
}

input[type="text"] {
  font-family: 'Varela Round', sans-serif;
}

.text {
  font-family: 'Varela Round', sans-serif;
}

.closeBtn {
  color: #cccccc;
  float: right;
  font-size: 30px;
}

.closeBtn:hover,
.closeBtn:focus {
  color: #000000;
  text-decoration: none;
  cursor: pointer;
}

.bg-modal {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  position: absolute;
  top: 0;
  justify-content: center;
  align-items: center;
  display: none;
  filter: blur(0px);
}

.modal-content {
  background-color: #f4f4f4;
  width: 600px;
  height: 600px;
  border-radius: 6px;
  text-align: center;
  padding: 20px;
  margin-top: 30px;
  position: relative;
}

.class-input {
  width: 50%;
  display: block;
  margin: 8px auto;
}

.form-control {
  display: inline-block;
  width: 450px;
  height: 34px;
  padding: 6px 12px;
  font-size: 20px;
  font-family: Nunito, serif;
  line-height: 1.42857143;
  color: #555;
  background-color: #fff;
  background-image: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
  -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
  -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}

.comp-input {
  text-align: left;
  background-color: #fff!important;
  border: 1px solid #e0e0e0!important;
  height: 50px!important;
  padding-left: 15px;
  padding-right: 15px;
  border-radius: 3px!important;
}

.input-lg {
  height: 46px;
  padding: 10px 16px;
  font-size: 18px;
  line-height: 1.3333333;
  border-radius: 6px;
}

.sub-button {
  margin-top: 10px;
}

.container {
  display: flex;
  justify-content: center;
  align-self: center;
  transition: 1s;
  padding: 20px;
  position: relative;
  background: #ff4742;
}

.container .content {
  position: relative;
  max-width: 800px;
}
<link href="index.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Varela+Round&display=swap" rel="stylesheet"></link>
<h1 class="text">Boutique</h1>
<a id="revAddButton" role="button" target="_blank" class="btn btn-red text">Add a Comment</a>
<div class="bg-modal" id="modal">
  <div class="modal-content">
    <span class="closeBtn" id="closeBtn">&times;</span>
    <form action="">
      <h2 class="text">Add your comment</h2>
      <input class="class-input form-control comp-input input-lg" type="text" placeholder="Name" />
      <a role="button" href="/main" target="_blank" class="btn btn-red text sub-button">Submit</a>
    </form>
  </div>
</div>
Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70