This opens the modal when clicking on the first element with the class "today". How can I make it open when clicking all elements with class "today"?
// Get the modal and the open-modal-button
var modal = document.getElementById("modal");
var btn = document.getElementsByClassName("today")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {modal.style.display = "block";}
<tr>
<td class="rowspan" rowspan="2">1</td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
</tr>
<tr>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
<td class="today"></td>
</tr>
Updated Figuring this out: The 100 boxes now open the modal and I'd like the button I have added to the modal to color the element which was clicked.
I unfortunately have no clue how to do this except thinking of the using "This" ?!!?
Code now looks like this:
// Get the modal and the open-modal-buttons
var modal = document.getElementById("modal");
var btns = document.getElementsByClassName("today");
var btnsLength = btns.length
for (var i = 0; i < btnsLength; i++) {
btns[i].onclick = function () {
modal.style.display = "block";
};
}
<!-- The Modal -->
<div id="modal">
<!-- Modal content -->
<div class="modal-content">
<button id="color"></button>
</div>
</div>