UNPKG

apex4x

Version:

The Comprehensive ARIA Development Suite

41 lines 2.75 kB
�� Function: closest(domElementOrCSSSelector, functionConfirm(domElement)) Shorthand: parent(domElementOrCSSSelector, functionConfirm(domElement)) Description: Returns the matching parent element, or null if not found. Returns: domElement, or $A object if chained. Note: When the second parameter is undefined, closest() returns the parent DOM element. When the second parameter is set to a function however, it must return true in order for the current node to be returned. This exists for cases when specific criteria are needed, such as a matching tag name or element type. Example: // Return the parent DOM element. var myElement = $A.closest(domElement); //Or var myElement = $A.closest("#elementId"); // Return the parent DOM element, but only when specific criteria is confirmed. var myElement = $A.closest(domElement, function(node) { if (node.nodeName.toLowerCase() === "ul") return true; }); // Or the same using chaining // Return the parent DOM element. var myChain = $A(domElement).closest(); // Return the parent DOM element, but only when specific criteria is confirmed. var myChain = $A(domElement).closest(function(node) { if (node.nodeName.toLowerCase() === "ul") return true; }); // To return the modified element within a chain, use the "return()" method. var myElement = myChain.return();