Functiondojo.style

<script src="../../js/dojo.js"></script>
defined in dojo/_base/html.js

Accesses styles on a node. If 2 arguments are passed, acts as a getter. If 3 arguments are passed, acts as a setter.

Usage

function (/*DomNode|String*/ node, /*Object?*/ style, /*String?*/ value) (view source)
parametertypedescription
nodeDomNode|Stringid or reference to node to get/set style for
styleObjectOptional. the style property to set in DOM-accessor format ("borderWidth", not "border-width") or an object with key/value pairs suitable for setting each property.
valueStringOptional. If passed, sets value on the node for style, handling cross-browser concerns.

Examples

Example 1

Passing only an ID or node returns the computed style object of the node:

dojo.style("thinger");

Example 2

Passing a node and a style property returns the current normalized, computed value for that property:

dojo.style("thinger", "opacity"); // 1 by default

Example 3

Passing a node, a style property, and a value changes the current display of the node and returns the new computed value

dojo.style("thinger", "opacity", 0.5); // == 0.5

Example 4

Passing a node, an object-style style property sets each of the values in turn and returns the computed style object of the node:

dojo.style("thinger", {
    "opacity": 0.5,
    "border": "3px solid black",
    "height": 300
});

Example 5

When the CSS style property is hyphenated, the JavaScript property is camelCased. font-size becomes fontSize, and so on.

dojo.style("thinger",{
    fontSize:"14pt",
    letterSpacing:"1.2em"
});

Example 6

dojo.NodeList implements .style() using the same syntax, omitting the "node" parameter, calling dojo.style() on every element of the list. See: dojo.query and dojo.NodeList

dojo.query(".someClassName").style("visibility","hidden");
// or
dojo.query("#baz > div").style({
    opacity:0.75,
    fontSize:"13pt"
});