jQuery-检查子div是否可见 [英] jQuery - Check if child div is visible

查看:59
本文介绍了jQuery-检查子div是否可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查看li的子div是否可见,如果可以的话,将一个类应用于li.这是我得到的,但不起作用.

I'm trying to see if the the child div of an li is visible and if so apply a class to the li. This is what I got but it's not working.

if(jQuery('#menu li').children('div').css('display') != 'none') {
    jQuery('li', this).addClass('dropHover');
}

推荐答案

if (jQuery('#menu li > div').is(':visible')){
    //...
    jQuery('li', this).addClass('dropHover');
}

我不知道什么是DOM结构或this所指的是什么,但这也可以解决问题:

I don't know what is the DOM structure or to what this refers to, but this might do the trick as well:

jQuery('#menu li:has(div:visible)').addClass('dropHover');

它将类"dropHover"添加到所有具有可见<div>
<li>元素 并且它们必须是具有菜单ID的元素的子元素.

    It adds the class "dropHover" to all <li> elements that have a visible <div>
and they need to be children of an element with the menu id.

这篇关于jQuery-检查子div是否可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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