开发者

removeClass jquery statement not working

开发者 https://www.devze.com 2022-12-23 07:35 出处:网络
I have the following JQuery statement and it is adding the class \'current\'开发者_如何转开发 but it is not removing the class form the siblings.

I have the following JQuery statement and it is adding the class 'current'开发者_如何转开发 but it is not removing the class form the siblings.

Any ideas why?

$('.page_link[longdesc=' + page_num + ']')
  .addClass('current').siblings('.current').removeClass('current');

Malcolm


Without your HTML markup, I'm guessing your classes aren't direct siblings but wrapped in something (to give them a border maybe?) In that case, .siblings() isn't finding anything.

In any case, it might be simpler to just remove current from all class="page_link" elements without caring where they are, like this:

$(".page_link.current").removeClass('current');
$('.page_link[longdesc=' + page_num + ']').addClass('current');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号