Skip to content

cy.elements(query?)

cy.elements — Core > Accessing elements. Cytoscape.js signatures, parameters and return contract.

cy.elements — Core › Accessing elements

Preview · Core › Accessing elements

Read in the complete API reference · All API members

// Get all nodes and edges, or only those matching a query
cy.elements(query?: FilterLike<NodeData, EdgeData>): Collection<NodeData, EdgeData>

Get all nodes and edges, or only those matching a query. Nodes appear first, in insertion order, followed by edges.

Pass a query object such as { selected: true, data: { score: { gt: 2 } } } or a predicate such as ele => ele.data('score') > 2. Unknown query keys and selector strings throw.

Collections preserve their membership while reading current element values. Query again to include newly matching elements. Calls without a query return the same collection object until an element is added or removed.

Parameters
NameDescription
query: FilterLike<NodeData, EdgeData>?

a query object or an ( ele) => boolean predicate; omit for everything

Fields of query
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 Collection<NodeData, EdgeData>

the matching elements

Example

console.log(cy.elements().map(ele => ele.id())); // ["a","b","c","ab","bc"]

Example graph and handle setup