This code isn't working as expected. It is not showing any text inside of span.day where it should be showing today's day (Tuesday at the time of writing). It is also not properly adding the class "currentDay" inside of the $.each
callback.
$('#showLess span.day').innerHTML=weekday[today];
$.each($('#showMore p span.day'), function(index, item) {
if(typeof item.innerHTML != 'undefined')
{
alert('item.text:' +item.innerHTML);
alert('weekday[today]'+item.innerHTML.indexOf(weekday[today]));
if(item.innerHTML.indexOf(weekday[today])!=-1) {
alert("check which element has added class currentDay:");
item.addClass('currentDay');
}else{
if(item.hasClass('currentDay')) {
item.removeClass('currentDay');
}
}
}
});
.innerHTML
is not changing the HTML, additional class is not getting added as expected.
<p id="showLess" class="less">
<span class="day">**Tuesday**</span>
</p>
Why isn't the day showing?
Why is the show/hide not working?
$('.less').on('click', function(e) {
$('#showMore').show();
$('#showLess').hide();
});
$('.more').bind('click', function(e) {
$('#showLess').show();
$('#showMore').hide();
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…