检查DOM中是否存在现有的jQuery对象(而不是选择器) [英] Check if existing jQuery object (not a selector) exists in the DOM
本文介绍了检查DOM中是否存在现有的jQuery对象(而不是选择器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
var $doesNotYetExistInTheDOM = $('<span/>'); // create new jQuery element
// outside of the DOM
var $doesExistInTheDOM = $('span'); // selected element from the DOM
有没有办法检查一个 jQuery 所选对象存在于 DOM ?
推荐答案
您可以通过尝试找到它文件:
You can check by trying to find it in the document:
!!$(document).find($doesNotYetExistInTheDOM).length // false
!!$(document).find($doesExistInTheDOM).length // true
这篇关于检查DOM中是否存在现有的jQuery对象(而不是选择器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文