你如何比较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屋!
查看全文