Skip to content

Style

Read resolved styling and manage supported bypasses.

#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.

#eles.removeStyle()

// Remove all keys
eles.removeStyle(): this

Remove per-element style bypasses from every element. Values return to those supplied by the stylesheet, including any configured transitions.

Returns this

this collection, for chaining

Example

cy.style({ bypasses: { a: { width: 60 } } });
cy.getElementById('a').removeStyle();
console.log(cy.getElementById('a').width()); // 30

Example graph and handle setup

#eles.removeStyle(name)

// Remove the specified keys
eles.removeStyle(name: string): this

Remove per-element style bypasses from every element. Values return to those supplied by the stylesheet, including any configured transitions.

Parameters
NameDescription
name: string

the property to un-bypass, dash-case or camelCase; omit to clear each element's whole bypass declaration

Returns this

this collection, for chaining

Example

cy.style({ bypasses: { a: { width: 60 } } });
cy.getElementById('a').removeStyle('width');
console.log(cy.getElementById('a').width()); // 30

Example graph and handle setup

Also spelled eles.removeCss.

#ele.renderedStyle(name?)

// Like style(), but with length props (width, height, border-width, font-size) scaled into rendered (on-screen) px by the zoom
ele.renderedStyle(name?: string): unknown

Like style(), but with length props (width, height, border-width, font-size) scaled into rendered (on-screen) px by the zoom.

Parameters
NameDescription
name: string?

a property name; omit for the whole group

Returns unknown

the rendered-space value, or the whole group's props

Example

cy.zoom(2);
console.log(cy.getElementById('a').renderedStyle('width')); // 60

Example graph and handle setup

Also spelled eles.renderedCss.

#ele.numericStyle(name)

// The numeric value of a numeric style prop
ele.numericStyle(name: string): number | undefined

The numeric value of a numeric style prop.

Parameters
NameDescription
name: string

a numeric style property

Returns number | undefined

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

Example

console.log(cy.nodes().first().numericStyle('width')); // 30

Example graph and handle setup

Throws

if the prop resolves to a colour or a keyword rather than a number

#ele.effectiveOpacity()

// The rendered opacity: a node's own opacity times its ancestors' (the store keeps the folded value in the column); an edge's own opacity (edges have no parent)
ele.effectiveOpacity(): number | undefined

The rendered opacity: a node's own opacity times its ancestors' (the store keeps the folded value in the column); an edge's own opacity (edges have no parent).

Returns number | undefined

the opacity actually rendered, which is what transparent() tests against 0 — not the declared opacity style value, which style('opacity') reads; undefined when empty or removed

Example

console.log(eles.effectiveOpacity()); // 1

Example graph and handle setup

#ele.transparent()

// Whether the first element is fully transparent — its effective opacity, with compound ancestors folded in, is exactly 0
ele.transparent(): boolean

Whether the first element is fully transparent — its effective opacity, with compound ancestors folded in, is exactly 0.

Returns boolean

true when invisible through opacity

Example

console.log(eles.transparent()); // false

Example graph and handle setup

#ele.takesUpSpace()

// The space tier: shown elements occupy space — they join bb/fit and size their compound parents — even when visibility: 'hidden' keeps them from rendering
ele.takesUpSpace(): boolean

The space tier: shown elements occupy space — they join bb/fit and size their compound parents — even when visibility: 'hidden' keeps them from rendering. display-tier hide() clears it.

Returns boolean

whether the element occupies space — this can differ from visible(), which is the paint tier

Example

console.log(eles.takesUpSpace()); // true

Example graph and handle setup

#ele.interactive()

// Whether the element can be interacted with: visible and not pointer-transparent (events: 'no')
ele.interactive(): boolean

Whether the element can be interacted with: visible and not pointer-transparent (events: 'no').

Returns boolean

whether any pointer path will resolve to this element; it rides visible(), so an element hidden either way is inert

Example

console.log(eles.interactive()); // true

Example graph and handle setup

#ele.label()

// The node's resolved label text ('' when none)
ele.label(): string | undefined

The node's resolved label text ('' when none). To set the label, update the stylesheet or the data field it reads.

Returns string | undefined

the resolved text of the first element's label — '' when it has none (a labelled-but-empty label reads the same), and undefined when the collection is empty or the element was removed

Example

console.log(eles.label()); // ""

Example graph and handle setup

All guides · Alphabetical API index · Read continuously