Q:

Javascript Program to implement Modal Box

0

Javascript Program to implement Modal Box using Javascript.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<!DOCTYPE html>
<html>
<head>
<style>
.ModalBox {
    display: none; 
    position: fixed; 
    z-index: 1;
    padding-top: 100px;
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0,0.4);
}

.ModalData {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    color:orange;
    font-size:18px;
    font-weight:bold;
}

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

.Close:hover,
.Close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
</style>
</head>

<body>
<h2>Modal Box</h2>
<button id="Button">Open Modal</button>

<div id="modal" class="ModalBox">

<div class="ModalData">
<span class="Close">&times;</span>
<p>Hello TutorialsLink!</p>
</div>

</div>

<script>
var popupmodal = document.getElementById('modal');

var btn = document.getElementById("Button");

var close = document.getElementsByClassName("Close")[0];

btn.onclick = function() {
    popupmodal.style.display = "block";
}

close.onclick = function() {
    popupmodal.style.display = "none";
}

window.onclick = function(event) {
    if (event.target ==  popupmodal) {
         popupmodal.style.display = "none";
    }
}
</script>

</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now