Plugin Author
edo888
(@edo888)
Hi,
I have checked your website and I have noticed the following code which is messing the on click event listeners on the flags:
function upDateYear() {
const date = new Date();
var currentYear = date.getFullYear();
var head = document.getElementsByTagName("HEAD");
head[0].innerHTML = head[0].innerHTML.replace(/CurrentYear/g, currentYear);
var body = document.getElementsByTagName("BODY");
body[0].innerHTML = body[0].innerHTML.replace(/CurrentYear/g, currentYear);
}
The problem is that when you reset innerHTML for the whole body, it removes all the javascript events from all elements, so it causes issues. Please ask your developer to fix it.
Thanks! 🙂
Thanks, you are right, all events are lost, here is the solution:
function upDateYear() {
const date = new Date();
const currentYear = date.getFullYear();
// Update HEAD content
const head = document.getElementsByTagName("HEAD")[0];
if (head) {
head.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(/CurrentYear/g, currentYear);
}
});
}
// Update the content of the BODY
const body = document.getElementsByTagName("BODY")[0];
if (body) {
const replaceTextNodes = node => {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(/CurrentYear/g, currentYear);
} else if (node.nodeType === Node.ELEMENT_NODE) {
node.childNodes.forEach(replaceTextNodes);
}
};
replaceTextNodes(body);
}
}