Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3866 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
mrt. 15
3593
1
mrt. 20
13612
0
dec. 19
2559
7
dec. 24
25772
0
mrt. 15
4237