你会如何比较 jQuery 对象? [英] How would you compare jQuery objects?
本文介绍了你会如何比较 jQuery 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想弄清楚如何比较两个 jQuery 对象,看看父元素是否是页面的主体.
So I'm trying to figure out how to compare two jQuery objects, to see if the parent element is the body of a page.
这是我所拥有的:
if ( $(this).parent() === $('body') ) ...
我知道这是错误的,但如果有人理解我的意思,他们能指出我正确的做法吗?
I know this is wrong, but if anybody understands what I'm getting at, could they point me towards the correct way of doing this?
推荐答案
你需要比较原始的DOM元素,例如:
You need to compare the raw DOM elements, e.g.:
if ($(this).parent().get(0) === $('body').get(0))
或
if ($(this).parent()[0] === $('body')[0])
这篇关于你会如何比较 jQuery 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文