Given two jQuery objects a and b, find whether b is within a
See
<a href="http://groups.google.com/group/jquery-en/browse_thread/thread/9efd1af2e2076eb9">http://groups.google.com/group/jquery-en/browse_thread/thread/9efd1af2e2076eb9</a>
Is this a bug?
test("Given two jQuery objects a and b, find whether b is within a. Test 1: b not within a", function() {
//b is not within a
//expect 0
var a = jQuery('<div id="a"></div>');
var b = jQuery('<div id="b"></div>');
equals( jQuery(b[0], a[0]).length, 0 );
equals( a.find(b[0]).length, 0 );
equals( jQuery(b).parents().filter(function() { return this === a[0]; }).length , 0 );
});
test("Given two jQuery objects a and b, find whether b is within a. Test 2: b within a", function() {
//b is within a
//expect 1
var a = jQuery('<div id="a"><div id="b"></div></div>');
var b = a.find("#b");
equals( jQuery(b[0], a[0]).length, 1 );
equals( a.find(b[0]).length, 1 );
equals( jQuery(b).parents().filter(function() { return this === a[0]; }).length , 1 );
});
I'm getting a false positive on
jQuery(b[0], a[0]).length
and a false negative on
a.find(b[0]).length
Thanks.
- Richard