How to cycle through siblings using jQuery?

前端 未结 4 1335
南旧
南旧 2020-12-11 18:24

I have the folowing code:

html:

A
B<
4条回答
  •  轮回少年
    2020-12-11 19:05

    how about this.

    ...
    var selected = $(".selected").removeClass("selected");
    if (jQuery(selected).next().addClass("selected").length == 0
       {jQuery(selected).siblings().first().addClass("selected");};
    ...
    

    In old good AI manner you try to do the deed (addClass), if it worked (length <> 0) nothing more to do, otherwise you try again on the first of the siblings.

提交回复
热议问题