Hi I have this working function (have some problems) but I wonder if I can improve on it o change the way of how it works
Explanation:
this function takes text Content of a div compare it to a current day at hand then it does the if on it and show certain icons according if the condition is met or not.
Example
if today is 29.2 the text content of the div is 29 and I want to show the icons only if the day is old so if the date is like future or tomorrow I want the icons to be hidden … the problem that I am facing btw is this logic works until the month switch to new month and the problem is that the new month numbers are like 1.2.3 small numbers so the icons show up because the if looks at bigger than the current day not smaller ..
any idea how to keep them hidden
protentional complex solution
making a hidden span inside every div which will show the day and the month and then make the logic filter according to month/day rather then only day!! too complex right do you have any more simple idea ?
to do this job.
//hide Task controle (archive Trash) if day is older than today
function hideIcons() {
// Extermal lets !!! already defined Trash and Archive Array style too !! FIX!!!
let divs = document.getElementsByClassName('day-number');
let trash = document.getElementsByClassName('fa-trash-alt');
let archive = document.getElementsByClassName('fa-archive');
let today = new Date();
let s = today.getDate()
for (let i = 0; i < divs.length; i++) {
(() => {
if (divs[i].textContent >= s) {
trash[i].style.display = 'none';
archive[i].style.display = 'none';
};
})(i);
}
};
hideIcons();
<span class="day-number"></span>
question from:
https://stackoverflow.com/questions/65948148/alternative-way-to-show-certain-icons-according-to-date-using-if-statement 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…