I've created a website which works exactly how it should in Chrome, but it does not working in IE11. When a button is pressed a popup should appear above the button with text from the HTML (this work perfectly in Chrome)
When running on IE11 I get this error:
SCRIPT5007: Unable to get property 'toggle' of undefined or null reference
script.js (3,3)
This points torwards my js file (called script.js):
function myFunction(data) {
var popup = document.getElementById("myPopup"+data);
popup.classList.toggle("show");
}
The error appears when I click the button to view the popup, the function get called only when I press the button.
Is there a way to get this to work in IE11 as well as Chrome?
See below for snippet on how the popup should work in IE11.
function myFunction(data) {
var popup = document.getElementById("myPopup" + data);
popup.classList.toggle("show");
}
/* Popup container */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
width: 100%;
padding-top: 15px;
padding-bottom: 15px;
background: white;
border: none;
font-size: 25px;
}
.popup:hover {
background-color: #008CBA;
color: white;
}
/* The actual popup (appears on top) */
.popup .popuptext {
visibility: hidden;
width: 250px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 110%;
left: 30%;
margin-left: -80px;
font-size: 16px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Toggle this class when clicking on the popup container (hide and show the popup) */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
-moz-animation: fadeIn 1s;
-ms-animation: fadeIn 1s;
animation: fadeIn 1s;
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<table>
<tr>
<th colspan="4">Test Buttons</th>
</tr>
<tr>
<td><button class="popup" onclick="myFunction(1)">1<span class="popuptext" id="myPopup1">Test Button 1</span></button></td>
<td><button class="popup" onclick="myFunction(2)">2<span class="popuptext" id="myPopup2">Test Button 2</span></button></td>
<td><button class="popup" onclick="myFunction(3)">3<span class="popuptext" id="myPopup3">Test Button 3</span></button></td>
<td><button class="popup" onclick="myFunction(4)">4<span class="popuptext" id="myPopup4">Test Button 4</span></button></td>
</tr>
</table>
</body>
</html>