简体   繁体   中英

jquery hide ul element within parent ul of li

heres my code:

<ul class="table">      

<li class="dropdown">

    <a href="#" class="arrow">DROPDOWN ITEM</a>

</li>

<li class="hide">
<ul>

    <li class="row">THIS IS AN ITEM</li>    
    <li class="row">THIS IS ANOTHER ITEM</li>           

</ul>
</li>

</ul>

<ul class="table">      

<li class="dropdown">

    <a href="#" class="arrow">DROPDOWN ITEM</a>

</li>

<li class="hide">
<ul>

    <li class="row">THIS IS AN ITEM</li>    
    <li class="row">THIS IS ANOTHER ITEM</li>           

</ul>
</li>

</ul>

heres my jquery:

$('.arrow').click(function(event) {
    event.preventDefault();

    if ($(this).parents('ul:eq(0)').find('.hide').is(":visible"))
        $(this).parents('ul:eq(0)').find('.hide').attr('display', 'none');
    else
        $(this).parents('ul:eq(0)').find('.hide').attr('display', 'block');         
});

you can see what i am trying to do, however its not working. when the "arrow" class is clicked, i want it to hide the "hide" class if it is not already hidden, if it is hidden then i want it to hide it. this should only apply to the parent UL so its only hiding the "hide" li within.

'Display'不是属性-相反,您需要css('display','none')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM