<button data-target="simpleModal_1" data-toggle="modal">Dismiss modal with a custom button</button>
	<button data-target="simpleModal_2" data-toggle="modal">Dismiss modal with [&times;] button</button>
</p>


<div id="simpleModal_1" class="modal">
    <div class="modal-window">
	 <button data-dismiss="modal">Close</button>
        <h3>Dismiss with a custom button</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
       
    </div>
</div>
<div id="simpleModal_2" class="modal">
    <div class="modal-window small">
        <span class="close" data-dismiss="modal">&times;</span>
        <h3>Dismiss with [&times;] button</h3>

        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        <button data-dismiss="modal">Close</button>
    </div>
</div>

	.modal {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    display: none;
    overflow: auto;
    background-color: #000000;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 9999;
}

.modal-window {
    position: relative;
    background-color: #FFFFFF;
    width: 50%;
    margin: 10% auto;
    padding: 20px;
}

.modal-window.small {
    width: 75%;
}

.modal-window.large {
    width: 75%;
}

.close {
    position: absolute;
    top: 0;
    right: 0;
    color: rgba(0,0,0,0.3);
    height: 30px;
    width: 30px;
    font-size: 30px;
    line-height: 30px;
    text-align: center;
}

.close:hover,
.close:focus {
    color: #000000;
    cursor: pointer;
}

.open {
    display: block;
}

	</style>

    <style>
        button { padding: 15px; font-size: 12px; background: indianred; color: #FFF; border: none }
        .subheading { font-style: italic }
   

document.addEventListener('click', function (e) {
    e = e || window.event;
    var target = e.target || e.srcElement;

    if (target.hasAttribute('data-toggle') && target.getAttribute('data-toggle') == 'modal') {
        if (target.hasAttribute('data-target')) {
            var m_ID = target.getAttribute('data-target');
            document.getElementById(m_ID).classList.add('open');
            e.preventDefault();
        }
    }

    // Close modal window with 'data-dismiss' attribute or when the backdrop is clicked
    if ((target.hasAttribute('data-dismiss') && target.getAttribute('data-dismiss') == 'modal') || target.classList.contains('modal')) {
        var modal = document.querySelector('[class="modal open"]');
        modal.classList.remove('open');
        e.preventDefault();
    }
}, false);




External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.