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.
here's what I have:
if ( $(this).parent() === $('body') ) ...
我知道这是不对的,但是如果有人明白我的意思,他们能给我指出正确的方法吗?
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.
here's what I have:
if ( $(this).parent() === $('body') ) ...
我知道这是不对的,但是如果有人明白我的意思,他们能给我指出正确的方法吗?
You need to compare the raw DOM elements, e.g.:
if ($(this).parent().get(0) === $('body').get(0))
或
if ($(this).parent()[0] === $('body')[0])