Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查jquery中是否存在div_Jquery - Fatal编程技术网

检查jquery中是否存在div

检查jquery中是否存在div,jquery,Jquery,我认为上面这样的东西是我所需要的,但我不知道if语句部分应该如何工作 我希望检查某个div是否存在,如果存在,请在单击代码时运行以下jQuery 更新1 if(.is-open close-now){ jQuery(".extra_div").click(function($){ alert('"Sorry, this takeaway only accepts orders during its opening hours"'); }); } 这两个分

我认为上面这样的东西是我所需要的,但我不知道if语句部分应该如何工作

我希望检查某个div是否存在,如果存在,请在单击代码时运行以下jQuery

更新1

if(.is-open close-now){
jQuery(".extra_div").click(function($){
            alert('"Sorry, this takeaway only accepts orders during its opening hours"');
        });
}
这两个分区是

现在开门吗?开门
.is open close now-close

您可以轻松地检查其
长度
。如果某个元素不存在,则检查其
长度将返回false
if($('.is open').length){
//存在
log('is-open exists');
//做事
}
如果($('.not是打开的')。长度){
//不存在
log('not-is-open-exists');
//做事
}


div是否始终存在且可能隐藏?或者,如果时间在工作时间之外,则div在页面上不存在?状态签入DOM:if($(选择器div).length){对不起,我是在之后接的这个工作,但是从我所知道的情况来看,如果它已经关闭并且有上面的分区,那么另一个分区根本就不存在大致上我想要的是什么,但是我用两个分区更新了帖子,本质上是这个,但我换了我的分区吗
if ($(.is-open close-now).length){
jQuery(".extra_div").click(function($){
            alert('"Sorry, this takeaway only accepts orders during its opening hours"');
        });
}