Count ul tags that are children

北战南征 提交于 2020-01-06 08:25:07

问题


In this list, how can I count how many ul tags there are below the li.selected? I want ul tags from all levels counted, not just direct children. The return in this example should be 2.

<ul class="theMenu">
<li>
    <a href="">Great Britain</a>
    <ul>
        <li>
            <a href="">London</a>
            <ul>
                <li><a href="">Trafalgar Square</a></li>
                <li><a href="">White Heart Lane</a></li>
                <li><a href="">Paddington Station</a></li>
            </ul>
        </li>
    </ul>
</li>
<li><a href="">Germany</a></li>
<li>
    <a href="">France</a>
    <ul>
        <li class="selected">
            <a href="">Paris</a>
            <ul>
                <li><a href="">Notre Dame</a></li>
                <li>
                    <a href="">Parc des Princes</a>
                    <ul>
                        <li><a href="">Zlatan Ibrahimovic</a></li>
                    </ul>
                </li>
                <li><a href="">Sacre Coeur</a></li>
            </ul>
        </li>
        <li><a href="">Rouen</a></li>
        <li><a href="">Lyon</a></li>
        <li><a href="">Marseilles</a></li>
    </ul>
</li>
<li><a href="">Sweden</a></li>
<li><a href="">Poland</a></li>

Cheers / Robin.

来源:https://stackoverflow.com/questions/22235372/count-ul-tags-that-are-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!