type

Style

src @Js
class Style : Obj

Style models CSS style properties for an Elem.

fields

classes

The CSS classes for this element.

methods

addClass

Add the given CSS class name to this element.

addPseudoClass

Add a psuedo-class CSS definietion to this element.

clear

Clear all style declarations.

computed

Get the computed property value.

effective

Get the effetive style property value, which is the most specific style or CSS rule in effect on this node.

get

Get the given property value.

hasClass

Return true if this element has the given CSS class name, or false if it does not.

removeClass

Remove the given CSS class name to this element.

set

Set the given propery value.

setAll

Set all the given property values.

setCss

Set properties via CSS text.

toggleClass

Toggle the presence of the given CSS class name based on the cond argument

trap

Get or set an attribute.

Slot Details

addClass

src This addClass(Str name)

Add the given CSS class name to this element. If this element already contains the given class name, then this method does nothing. Returns this.

addPseudoClass

src Str addPseudoClass(Str name, Str css)

Add a psuedo-class CSS definietion to this element. A new class name is auto-generated and used to prefix name, name must start with the : character. Returns the generated class name.

style.addPseudoClass(":hover", "background: #eee")

classes

src Str[] classes

The CSS classes for this element.

clear

src This clear()

Clear all style declarations.

computed

src Obj? computed(Str name)

Get the computed property value.

effective

src Obj? effective(Str name)

Get the effetive style property value, which is the most specific style or CSS rule in effect on this node. Returns null if no rule in effect for given property.

This method is restricted to stylesheets that have originated from the same domain as the document. Any rules that may be applied from an external sheet will not be included.

get

src @Operator
Obj? get(Str name)

Get the given property value.

color := style["color"]

hasClass

src Bool hasClass(Str name)

Return true if this element has the given CSS class name, or false if it does not.

removeClass

src This removeClass(Str name)

Remove the given CSS class name to this element. If this element does not have the given class name, this method does nothing. Returns this.

set

src @Operator
This set(Str name, Obj? val)

Set the given propery value. If val is null this property is removed.

style["color"] = "#f00"

setAll

src This setAll(Str:Obj? map)

Set all the given property values.

style.setAll(["color":"#f00", "font-weight":"bold"])

setCss

src This setCss(Str css)

Set properties via CSS text.

style.setCss("color: #f00; font-weight: bold;")

toggleClass

src This toggleClass(Str name, Bool? cond := null)

Toggle the presence of the given CSS class name based on the cond argument:

  • null: remove class if present, or add if missing
  • true: always add class (see addClass)
  • false: always remove class(see removeClass)

trap

src virtual override Obj? trap(Str name, Obj?[]? args := null)

Get or set an attribute. Attribute names should be specifed in camel case:

style->backgroundColor == style["background-color"]