Skip to content

API reference

eles.style — Collection > Style. Cytoscape.js signatures, parameters and return contract.

eles.style — Collection › Style

Preview · Collection › Style

Read in the complete API reference · All API members

#ele.style()

// Get all style
ele.style(): unknown

Resolved style read off the stored channels — all of the first element's group props.

Returns unknown

the whole group's props (numbers for numeric props, rgb()/rgba() strings for colors, keywords otherwise), or undefined when the collection is empty

Example

console.log(cy.nodes().first().style()['background-color']); // "rgb(153,153,153)"

Example graph and handle setup

#ele.style(name)

// Get style by name
ele.style(name: string): unknown

Resolved style read off the stored channels — one value. A bypassed prop reads its bypass value, since a bypass writes stored truth.

Parameters
NameDescription
name: string

the property to read, dash-case or camelCase

Returns unknown

the resolved value, or undefined when the collection is empty or the prop belongs to the other group

Example

console.log(cy.nodes().first().style('background-color')); // "rgb(153,153,153)"

Example graph and handle setup

#eles.style(name, value)

// Set style by name
eles.style(name: string, value: unknown): this

Set a per-element style bypass on every element. Sugar over the stylesheet's bypasses section: the value must be a constant (mappers belong in the sheet's group blocks), the entry is keyed by the element's id and survives remove/re-add, it beats every sheet rule including the default sheet's selection color, and it exports from cy.json().

Parameters
NameDescription
name: string

the property to bypass, dash-case or camelCase

value: unknown

the constant value to pin

Returns this

this collection, for chaining

Example

const result = eles.style('width', 40);
console.log(result === eles); // true

Example graph and handle setup

Throws

on a mapper value, a global font prop, a transition config prop, a wrong-group prop, or an invalid value

#eles.style(props)

// Set several style fields
eles.style(props: Record<string, unknown>): this

Set several per-element style bypasses on every element. The object form of the setter: each key–value pair joins the element's bypass declaration.

Parameters
NameDescription
props: Record<string, unknown>

prop → constant value, dash-case or camelCase keys

Returns this

this collection, for chaining

Example

eles.style({ width: 40 });
console.log(eles.first().numericStyle('width')); // 40

Example graph and handle setup

Throws

as the name/value form does, per prop

Also spelled eles.css.