Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Finds the nearest ancestor of the element that passes the test.


{section}
{column:width=70%}

Finds the nearest ancestor of the element that passes the test.

{code:javascript|borderStyle=none|bgColor=white}
fluid.findAncestor(element, test);
File name:

{code}

*File name:* {{Fluid.js

Parameters

}}

h2. Parameters

{span:class=borderless-table
}
|*{{element}}*| (Element) DOM
element
 element |
|*{{test}}*| (Function) A function which takes an element as a parameter and returns true or false for some test
.

Return Value

Div
class
Wiki Markup
{div:class=api-page
}

h1. fluid.findAncestor(element, test)
Section
Column
width70%
Code Block
javascriptjavascript
bgColorwhite
borderStylenone
Span
class

element

test

Span
classborderless-table

Element

the nearest ancestor that passes the test

Column
width5%
Column

See Also

Example

Code Blockjavascriptjavascript
. |
{span}

h2. Return Value
{span:class=borderless-table}
|*Element*| the nearest ancestor that passes the test |
{span}

{column}

{column:width=5%}
{column}

{column}
h3. See Also

{column}
{section}
----

h3. Example
{code:javascript}
var smallHeader = fluid.jById(id);
var bigHeader = fluid.findAncestor(smallHeader, function (element) {
    return $(element).is(selectors.sortHeader);
});
{code}
In this example, {{fluid.findAncestor()}} is used to find an ancestor of {{smallHeader}} that has a desired selector.

{div}