如何检查页面上是否已存在具有ID的对象? [英] How to check if an object with an ID already exists on the page?

查看:116
本文介绍了如何检查页面上是否已存在具有ID的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

是否存在“存在” jQuery的函数

比如说你有div:

<div id="hello"></div>

您正在动态创建一个div:

And you are dynamically creating a div:

<div id="hello"></div>

是否有一个可以在Jquery中使用的函数,它将检查具有ID的对象是否是你正在尝试创建已存在于页面上?

Is there a function you can use in Jquery which will check to see if the object with the ID you are trying to create already exists on the page?

推荐答案

对于jQuery方法,您可以使用

For jQuery method you could go with

if($("#selector").length) {
    //object already exists
}

这篇关于如何检查页面上是否已存在具有ID的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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