开发者

jQuery Hide All Children of Each Div Except First

开发者 https://www.devze.com 2023-04-12 19:52 出处:网络
I have this layout: <div class=\"list\"> <ul></ul> <ul></ul> </div> <div class=\"list\">

I have this layout:

<div class="list">
    <ul></ul>
    <ul></ul>
</div>
<div class="list">
    <ul></ul>
    <ul></ul>
    <ul></ul>
    <ul></ul>
</div>
<div class="list">
    <ul></ul>
    <ul></ul>
</div>

I am trying to only show the first ul of every div using jQuery. I know it is possible but when using $('div.list ul:gt(开发者_JAVA技巧1)').each(function(){$(this).hide()}); it shows the first div's contents and hides everything else.


Fiddle: http://jsfiddle.net/y9bEG/3/

Use this:

$("div.list").each(function(){
    $("ul:not(:first)", this).hide();
});

It selects each div element with class list, and hides all <ul> elements which are not a first element.

0

精彩评论

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

关注公众号