Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3389 Visualizzazioni

How do I set a condition to pop-up a block when we click a button using the HTML/CSS editor?

Thanks in advance.

Avatar
Abbandona
Risposta migliore

Hi,

You can use the following code to raise a pop-up

HTML:

<button id="popupButton">Click Me</button>
<div id="popupBlock" class="hidden">
  <!-- Content of the popup goes here -->
  <p>This is the popup content.</p>
</div>




CSS:
#popupBlock {
  display: none; /* Initially hidden */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px;
  background-color: #fff;
  border: 1px solid #ccc;
}

Javascript:

<script>
const popupButton = document.getElementById('popupButton');
const popupBlock = document.getElementById('popupBlock');

popupButton.addEventListener('click', function() {
popupBlock.classList.toggle('hidden');
  });
</script>




Hope it helps

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
mar 15
3309
1
mar 20
13285
0
dic 19
2319
7
dic 24
25326
0
mar 15
3968