Skip to content

cy.getElementById(id)

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

cy.getElementById — Core › Accessing elements

Preview · Core › Accessing elements

Read in the complete API reference · All API members

// Look up one element by id through the O(1) id index
cy.getElementById(id: string): Collection<NodeData, EdgeData>

Look up one element by id through the O(1) id index.

Parameters
NameDescription
id: string

the element id

Returns Collection<NodeData, EdgeData>

a collection of one element, or an empty collection when no element has that id

Example

console.log(cy.getElementById('a').id()); // 'a'

Example graph and handle setup

Also spelled cy.$id, cy.byId.