I have a schedule that I want to hide when all days of the week are closed. So I did this function that analyzes if the content of the day is Closed and if all 7 days have Closed it hides the agenda.
$( document ).ready(function() {
var statusClosed = $('.agenda-status').html();
if (statusClosed === 'Fechado') {
$('.agenda-dia').addClass('dia-fechado');
var semanaFechada = $('.agenda-semanal .dia-fechado').length;
if( semanaFechada >= 7 ) {
$('.agenda-semanal').addClass('semana-fechada');
$('.semana-fechada').hide();
}
}
});
It turns out that when every day of the calendar is closed it works, but if the first day is open it does not run the function. I believe it's because of .html () only doing the search in the first element.
How do I get it to search all the elements ".agenda-status" and not only in the first one?
<li class="agenda-dia ">
<a href="javascript:;" data-type="Fechado">
<span class="dia-semana Domingo">Domingo</span>
<em class="agenda-status">Fechado</em>
</a></li>