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

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

So I start with items 1-4:

Lorem
4条回答
  •  借酒劲吻你
    2020-11-28 11:01

    You could do this two ways: You could add another class for the display: none elements and make them invisible via css, or you could find out the css property via jquery

    via css class

    html

    
    
    Lorem
    Ipsum

    css

    .someDiv{
        display: block;
    }
    
    .hidden{
        display: none;
    }
    

    js

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

    via jquery

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

提交回复
热议问题