Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
3361 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
bře 15
3287
1
bře 20
13265
0
pro 19
2303
7
pro 24
25314
0
bře 15
3961