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

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

So I start with items 1-4:

Lorem
4条回答
  •  执念已碎
    2020-11-28 10:42

    You can use the :visible selector to find only visible.

    $(".someDiv:visible").each(....);
    

    You can use the .not() selector to find only hidden.

    $(".someDiv").not(":visible").each(....);
    

    I think you can perform the same operation in your code with this one line.

    $(".someDiv").hide().find(".regular").show();
    

    Find all .someDiv and hide them, then find those with a .regular class and show them.

提交回复
热议问题