Skip to content

Comparison

Compare collections without mutating the graph.

#eles.same(other)

// Whether both collections hold exactly the same elements, ignoring order
eles.same(other: Collection): boolean

Whether both collections hold exactly the same elements, ignoring order.

Parameters
NameDescription
other: Collection

the collection to compare against

Returns boolean

true when the element sets are equal

Example

const other = cy.getElementById('b');
console.log(cy.getElementById('a').same(other)); // false

Example graph and handle setup

Also spelled eles.equal, eles.equals.

#eles.anySame(other)

// Whether the two collections share at least one element
eles.anySame(other: Collection): boolean

Whether the two collections share at least one element.

Parameters
NameDescription
other: Collection

the collection to compare against

Returns boolean

true when the sets intersect

Example

const other = cy.getElementById('b');
console.log(cy.getElementById('a').anySame(other)); // false

Example graph and handle setup

#eles.contains(other)

// Whether every element of other is also in this collection
eles.contains(other: Collection): boolean

Whether every element of other is also in this collection.

Parameters
NameDescription
other: Collection

the candidate subset

Returns boolean

true when other is contained

Example

const other = cy.getElementById('b');
console.log(cy.getElementById('a').contains(other)); // false

Example graph and handle setup

Also spelled eles.has.

#eles.allAreNeighbors(other)

// Whether every element of other is in this collection's neighborhood
eles.allAreNeighbors(other: Collection): boolean

Whether every element of other is in this collection's neighborhood.

Parameters
NameDescription
other: Collection

the elements to test

Returns boolean

true when all of them are neighbors

Example

const other = cy.getElementById('b');
console.log(cy.getElementById('a').allAreNeighbors(other)); // true

Example graph and handle setup

Also spelled eles.allAreNeighbours.

#eles.allAre(criterion)

// Whether every element matches the criterion
eles.allAre(criterion: FilterLike<NodeData, EdgeData, Data, NodeData | EdgeData>): boolean

Whether every element matches the criterion.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, Data, NodeData | EdgeData>

a query object or an ( ele) => boolean predicate (selector strings are not accepted)

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns boolean

true when all elements match

Example

console.log(cy.nodes().allAre(ele => ele.isNode())); // true

Example graph and handle setup

#eles.is(criterion)

// Whether any element matches the criterion
eles.is(criterion: FilterLike<NodeData, EdgeData, Data, NodeData | EdgeData>): boolean

Whether any element matches the criterion.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, Data, NodeData | EdgeData>

a query object or an ( ele) => boolean predicate

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns boolean

true when at least one element matches

Example

console.log(cy.getElementById('a').is(ele => ele.id() === 'a')); // true

Example graph and handle setup

All guides · Alphabetical API index · Read continuously