I'm making an online advent calendar where you can only open the door of the day. All the doors use JavaScript onclick to display offer eg, 'door10'...
<a href="javascript:void(0)" onclick = "document.getElementById('door10').style.display='block';document.getElementById('fade10').style.display='block'" id="door-10-link">
They're all created with this onclick and then at the end of the HTML the following JavaScript function runs which removes the href and onclick attributes of the doors that aren't today, thus removing the ability to open them.
function disableDoor(num) {
var today = new Date();
var day = today.getDate();
var calendar_day = num;
if (calendar_day == day) {
} else {
var string = "door-" + num + "-link";
var d = document.getElementById(string);
d.removeAttribute("href");
d.removeAttribute("onclick");
}
This all works fine in everything but Internet Explorer where the doors are still clickable even though they shouldn't be. The cursor doesn't change to the hover cursor and if you inspect the element the href and onclick values have been correctly removed, yet you can still 'open the door' even though no href is stated. The HTML now looks like this with the attributes correctly removed...
<a id="door-10-link">
In the IE inspector, if I 'Edit as HTML', don't change anything, click outside to finish editing and refresh the page it all works fine and I can't click the doors I'm not supposed to. The href element has been properly removed from the page.
It seems like the elements on the page need to refresh or something after the JavaScript has run. My guess is it's something to do with the DOM maybe but I'm pretty new to that area.
Any help would be brilliant as it's got me properly stumped.
Thanks in advance