JS Displays the parent directory based on the number of sub-directories

Source: Internet
Author: User

<li> quantity in Demand:<ul> is 0, do not show <ul> and <b>;<div> <ul> quantity is 0, do not show <div>

1.html Code

//<Divclass= "MyPerson"ID= "mypersonBtn">People Management</Div><Divclass= "mypersonClass"ID= "mypersonId">    <b>Spring and autumn Five tyrants</b>    <ul>    </ul>    <b>Three kingdoms</b>    <ul>        <Li><ahref="">Cao cao</a></Li>        <Li><ahref="">Liu bei</a></Li>        <Li><ahref="">Sun quan</a></Li>        <Li><ahref="">Zhuge liang</a></Li>        <Li><ahref="">Sima Yi</a></Li>        <Li><ahref="">Zhou yu</a></Li>        <Li><ahref="">Lu xun</a></Li>        <Li><ahref="">Guo Jia</a></Li>        <Li><ahref="">Xunyu</a></Li>        <Li><ahref="">Guan yu</a></Li>    </ul>    <b>Seven Warring states</b>    <ul>    </ul></Div>

2.js Implementation code (don't forget to introduce jquery)

Isshowmenu ("#Mypersonid"); functionIsshowmenu (ID) {$ (id). FIND (' UL '). each (function(ulobj) {varLicount = $ ( This). Find (' Li '). length; if(licount <= 0){                $( This). Prev (). CSS (' Display ', ' none '); $( This). Remove ();        }        }); //        varUlcount = $ (ID). FIND (' UL '). length; if(Ulcount <= 0) {$ (id). remove (); }    }

JS Displays the parent directory based on the number of sub-directories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.