Change JS to not write to classList directly

This commit is contained in:
Bruno Rybársky 2024-04-28 22:41:20 +02:00
parent 1c9f5cf3c0
commit 969009eed1

@ -12,6 +12,17 @@ function isLoggedIn() {
return UserInfo.Email && UserInfo.Email.length > 0;
}
async function setElementClasses(element, newClasses) {
// Ensure the element exists
if (!element) return;
// Clear all existing classes
element.className = '';
// Add the new classes to the element
element.classList.add(...newClasses);
}
async function handleResponse(data, successMessage, failureMessage) {
"use strict";
const statusMessageContainer = document.getElementById("statusMessageContainer");
@ -664,8 +675,8 @@ async function reloadMemeVotes(memeID) {
memeVoteDownvoteButtonElement.classList.add('visual_hover');
}
memeVoteUpvoteElement.classList = [`ri-arrow-up-circle-${memeUpvoteVariant}`];
memeVoteDownvoteElement.classList = [`ri-arrow-down-circle-${memeDownvoteVariant}`];
await setElementClasses(memeVoteUpvoteElement, [`ri-arrow-up-circle-${memeUpvoteVariant}`]);
await setElementClasses(memeVoteDownvoteElement, [`ri-arrow-down-circle-${memeDownvoteVariant}`])
}