removeClass未按预期工作

removeClass not working as expected

本文关键字:工作 removeClass      更新时间:2023-09-26

我一直在尝试针对我想在其上运行removeClass的下一组html元素。我尝试了许多不同版本的.next() .find() eq() :last,但似乎无法使其删除该类。

我篡改了我正在使用的代码。

我想删除第二组.tm-title h3,但从页面的源代码来看,它总是在那里——第一个tm-title h3:first被删除了,但无论我尝试了什么选择器组合,下一组似乎都不起作用。

选择器出现问题

var currentMonth = $('.curMonth').text();
var currentSplit = currentMonth.split(" ");
var curMonth = currentSplit[0].toLowerCase();
// find current month and hide div
$('.' + curMonth).removeClass('eventCal')
    .find('.tm-title h3:first')
    .removeClass('curMonth')
//now it is referring to the h3 element so .next() won't work as the second title is a sibling of first h3
    .end()
    .find('.tm-title h3')
    .removeClass('nextMonth');

演示:Fiddle