0

I found the following on w3schools. So I want the modal to show onclick h1 tag. How can I do that?

I understand just very little of js but I think I need to trigger event with onclick function. To do that I need to assign the event the correct place. But I dont know how.

So, I think its like this.

I first need to assign some code to get h-tag, then an id to the h1 class I use. Then I need to get the modal by id. after that I need to get the h1 tag (this I dont understand how to do).

I searched up and down on the internet and tried many things myself as a leyman, but its not so easy without knowing what to do.

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal"></div>

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
    modal.style.display = "none";
}
}
</script>

0 Answers0