back to Overview

.get()

Retrieves properties, attributes and styles from the list's first element.
Web module only.

Syntax Variants

list.get(name)
list.get(name, toNumber)
list.get(list)
list.get(list, toNumber)
list.get(map)
list.get(map, toNumber)

Parameters

name
the name of a single property or attribute to modify. Unprefixed names set properties, a '$' prefix sets CSS styles and '@' sets attributes. Please see the table above for special properties and other options.
list
in order to retrieve more than one value, you can specify several names in an array or list. get() will then return an object map containing the values.
map
if you specify an object that is neither list nor string, get() will use it as a map of property names. Each property name will be requested. The values of the properties in the map will be ignored. get() will then return a new object map containing of results.
toNumber
if 'true', get() converts all returned values into numbers. If they are strings, get() removes any non-numeric characters before the conversion. This is useful when you request a CSS property such as '$marginTop' that returns a value with a unit suffix, like "21px". get() will convert it into a number and return 21. If the returned value is not parsable as a number, NaN will be returned.
(return value)
if get() was called with a single name, it returns the corresponding value. If a list or map was given, get() returns a new object map with the names as keys and the values as values. It returns undefined if the list is empty.

Description

Retrieves properties, attributes and styles from the list's first element. The syntax to request those values is mostly identical with set(). You can either get a single value if you specify only one name, or get an object map when you specify several names using an array or an object map.

The name parameter defines what kind of data you are reading. The following name schemes are supported:

Name SchemaExampleSets what?Description
nameinnerHTMLPropertyA name without prefix of '$' or '@' gets a property of the object.
@name@hrefAttributeGets the HTML attribute using getAttribute().
%name%phoneData-AttributeGets a data attribute using getAttribute(). Data attributes are attributes whose names start with 'data-'. '%myattr' and '@data-myattr' are equivalent.
$name$fontSizeCSS PropertyGets a style using the element's style object. The syntax for the CSS styles is camel-case (e.g. "$backgroundColor", not "$background-color"). Shorthand properties like "border" or "margin" are not supported. You must use the full name, e.g. "$marginTop". Minified will try to determine the effective style and thus will return the value set in style sheets if not overwritten using a regular style.
$$CSS ClassesA simple $ returns the CSS classes of the element and is identical with "className".
$$$$StyleReads the element's style attribute in a browser-independent way. On legacy IEs it uses style.cssText, and on everything else just the "style" attribute.
$$show$$showShow/HideReturns 1 if the element is visible and 0 if it is not visible. An element counts as visible if '$visibility' is not 'hidden' and '$display' is not 'none'. Other properties will be ignored, even if they can also be used to hide the element.
$$fade$$fadeFade EffectThe name '$$fade' returns the opacity of the element as a value between 0 and 1. '$$fade' will also automatically evaluate the element's 'visibility' and 'display' styles to find out whether the element is actually visible.
$$slide$$slideSlide Effect'$$slide' returns the height of the element in pixels with a 'px' suffix and is equivalent to '$height'. Please note that you can pass that 'px' value to '$$slide' in set(), which will then set the according '$height'.
$$scrollX, $$scrollY$$scrollYScroll CoordinatesThe names '$$scrollX' and '$$scrollY' can be used on $(window) to retrieve the scroll coordinates of the document. The coordinates are specified in pixels without a 'px' unit postfix.

Example

Retrieves the id, title attribute and the background color of the element '#myElement':

var id = $('#myElement).get('id');
var title = $('#myElement).get('@title');
var bgColor = $('#myElement).get('$backgroundColor');

Example

Retrieves the id, title attribute and the background color of the element '#myElement' as a map:

var m = $('#myElement).get(['id', '@title', '$backgroundColor']);
var id = m.id;
var title = m['@title'];
var bgColor = m.$backgroundColor;

Example

Uses get() and set() to reposition an element:

var coords = $('#myElement').get({$top: 0, $left: 0}, true);
coords.$top = coords.$top + 10 + 'px';
coords.$left = coords.$left + 20 + 'px';
$('#myElement').set(coords);
Please note that the values of $top and $left in the get() invocation do not matter and will be ignored!

See also..

  • set() sets values using the same property syntax.

Comments

comments powered by Disqus

back to Overview

Functions