Do not understand why these functions supposedly point to the same object, but they return different results:
(1) with getSubMenu(..)
(2) with itemInSubMenu(..)
(1) traverses down hill with .find(..)
(2) traverses up hill with .parent()
What is wrong with the .next(..) statement? .find(..) works, but not .next(..)
PS:
FWIW, elsewhere I am TABbing from <li> to <li>.
When I encounter a <li.daddy> I call getSubMenu to show the sub-menu. After it shows, I continue tabbing, e.g.:
from:
<li>text23321</li>
<li>text23322</li>
I call getSubMenu on the 1st <li> and then itemInSubMenu on the 2nd <li> … and they generate un-equal sub-menu objects (“.aMenu”) … but they are in fact the same?
When TABbing encounters "li.daddy", getSubMenu is called and selects the very 1st (top) item in the sub-menu = text23321. getSubMenu returns the sub-menu object and stores it in a var.
TABbing continues to the 2nd item = text23322 in the same sub-menu and calls itemInSubMenu which returns a sub-menu object. Since we’re by definition in the same sub-menu, the object returned by getSubMenu and itemInSubMenu should be equal, but they are not?
As already mentioned, getSubMenu traverses down the DOM tree with .find and itemInSubMenu goes up with .parent.
Whether going down or up, shouldn’t the returned object be the same?
I will quote the 2 functions here, with corrections:
functions getSubMenu($currItem) {
var $theSubMenu = null;
if ( $currItem.hasClass("daddy") ) {
$theSubMenu = $currItem.find(".aMenu").first();
}
return $theSubMenu;
} // getSubMenu
function itsParentIsSubMenu($theItem) {
// .daddy <-- .aMenu <-- $theItem
return $theItem.parent().parent().hasClass("daddy");
} // itsParentIsSubMenu
function itemInSubMenu($theItem) {
var $theSubMenu = null;
if (itsParentIsSubMenu($theItem)) {
$theSubMenu = $theItem.parent(); // parent = ".aMenu"
}
return $theSubMenu;
} // itemInSubMenu
Absolutely no thanks to me, I found that i needed to add [0] to compare the contents of the 2 jQuery objects. AND that every time a jQuery object is created, it’s a brand new one so testing for equality of 2 jQuery objects always renders false (or, testing for in-equality always renders true).
It’s less “a birch is a tree” and more… “Something in this set is also in this other set”. More of a Venn Diagram assertion that the union is not empty;
cars.is("things that are blue") would return true - not all cars are blue, and not all things that are blue are cars, but at least one thing in the two sets is both.
Often used with single-element sets - element.is("li") - the thing you have selected (element) is a member of the set of elements returned by the selector “li”