jQuery:确定是否< li>包含< ul> [英] jQuery: determine if a <li> contains a <ul>

查看:107
本文介绍了jQuery:确定是否< li>包含< ul>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些HTML代码,其中包含嵌套的<ul>元素,我需要向每个包含子<ul><li>元素添加一个父"类.单个<li>可能直接包含多个元素,例如:

I have some HTML code that contains nested <ul> elements and I need to add a class 'parent' to each <li> element that contains a child <ul>. There could be more than one element contained directly withing a single <li>, e.g:

<li>
    <a>...</a>
    <span>...</span>
    <ul>...</ul>
</li>

我所需要做的就是确定特定的<li>是否包含<ul>作为子元素.

All I need is to determine if a particular <li> contains a <ul> as a child element.

我将如何处理?

推荐答案

这将满足您的要求:

$('li:has(> ul)').addClass('parent');

这篇关于jQuery:确定是否&lt; li&gt;包含&lt; ul&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆