使用javascript检查div是否不存在 [英] Check if a div does NOT exist with javascript

查看:26
本文介绍了使用javascript检查div是否不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查 div 是否存在相当简单

Checking if a div exists is fairly simple

if(document.getif(document.getElementById('if')){

}

但是如何检查具有给定 id 的 div 是否不存在?

But how can I check if a div with the given id does not exist?

推荐答案

var myElem = document.getElementById('myElementId');
if (myElem === null) alert('does not exist!');

这篇关于使用javascript检查div是否不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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