create a popup dialogue in javascript

To create a popup dialogue in JavaScript, you can use a modal or popup. Here's an example of how to create a modal popup using JavaScript, HTML, and CSS:

<!-- HTML -->
<button onclick="openModal()">Open Modal</button>

<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close" onclick="closeModal()">&times;</span>
    <p>This is a popup dialogue!</p>
  </div>
</div>
243 chars
10 lines
/* CSS */
.modal {
  display: none; 
  position: fixed; 
  z-index: 1; 
  left: 0;
  top: 0;
  width: 100%; 
  height: 100%; 
  overflow: auto; 
  background-color: rgba(0,0,0,0.4);
}

.modal-content {
  background-color: #fefefe;
  margin: 15% auto; 
  padding: 20px;
  border: 1px solid #888;
  width: 80%; 
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}
487 chars
35 lines
index.tsx
// JavaScript 
function openModal() {
  document.getElementById("myModal").style.display = "block";
}

function closeModal() {
  document.getElementById("myModal").style.display = "none";
}
190 chars
9 lines

This code creates a button which, when clicked, opens a modal containing a popup dialogue. The user can close the modal by clicking the "X" icon in the top right corner.

related categories

gistlibby LogSnag