Using jQuery, how do you find only visible elements and leave hidden elements alone?

后端 未结 4 1079
忘掉有多难
忘掉有多难 2020-11-28 10:03

So I start with items 1-4:

Lorem
4条回答
  •  时光说笑
    2020-11-28 10:58

    You could use :visible selector to select the .someDiv that are visible.

    $(".someDiv:visible").each(function(){
     if($(this).hasClass("regular")){
        $(this).show();
      } else {
        $(this).hide();
      }
    });
    

    Here is another funny way utilizing the chaining :) and making it single line.

    $('.someDiv:visible').not($('.someDiv.regular:visible')).hide();
    

提交回复
热议问题