.get()
Syntax Variants
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 Schema | Example | Sets what? | Description |
|---|---|---|---|
| name | innerHTML | Property | A name without prefix of '$' or '@' gets a property of the object. |
| @name | @href | Attribute | Gets the HTML attribute using getAttribute(). |
| %name | %phone | Data-Attribute | Gets a data attribute using getAttribute(). Data attributes are attributes whose names start with 'data-'. '%myattr' and '@data-myattr' are equivalent. |
| $name | $fontSize | CSS Property | Gets 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 Classes | A simple $ returns the CSS classes of the element and is identical with "className". |
| $$ | $$ | Style | Reads 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 | $$show | Show/Hide | Returns 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 | $$fade | Fade Effect | The 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 | $$slide | Slide 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 | $$scrollY | Scroll Coordinates | The 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 DisqusFunctions
- $() Web
- list.length Web, Util
- $$() Web
- $.getCookie()
- $.loop() Web
- $.off() Web
- $.parseJSON() Web
- $.ready() Web
- $.request() Web
- $.setCookie()
- $.toJSON() Web
- $.wait()
- .add() Web
- .addAfter() Web
- .addBefore() Web
- .addFront() Web
- .animate() Web
- .array() Util
- .call() Util
- .clone() Web
- .collect() Web, Util
- .contains() Util
- .dial() Web
- .each() Web, Util
- .endsWith() Util
- .equals() Util
- .fill() Web
- .filter() Web, Util
- .find() Web, Util
- .findLast() Web, Util
- .get() Web
- .hide() Web
- .ht()
- .intersection() Util
- .is() Web
- .join() Util
- .map() Util
- .merge() Util
- .next() Web
- .not() Web
- .offset()
- .on() Web
- .onChange() Web
- .onClick() Web
- .onFocus() Web
- .onOver() Web
- .only()
- .per() Util
- .reduce() Util
- .remove() Web
- .replace() Web
- .reverse() Util
- .select() Web
- .set() Web
- .show() Web
- .sort() Util
- .startsWith() Util
- .sub() Web, Util
- .text() Web
- .toObject() Util
- .toggle() Web
- .trav() Web
- .trigger() Web
- .uniq() Util
- .unite() Util
- .up() Web
- .values() Web
- EE() Web
- HTML() Web
- M Web, Util
- MINI.getter Web
- MINI.setter Web
- Minified Lists Web, Util
- Promise Web, Util
- _() Util
- _.bind() Util
- _.copyObj() Util
- _.dateAdd() Util
- _.dateClone() Util
- _.dateDiff() Util
- _.dateMidnight() Util
- _.eachObj() Util
- _.escapeHtml() Util
- _.escapeRegExp() Util
- _.extend() Util
- _.filterObj() Util
- _.format() Util
- _.formatHtml() Util
- _.formatValue() Util
- _.isBool() Util
- _.isDate() Util
- _.isEmpty() Util
- _.isFunction() Util
- _.isList() Util
- _.isNumber() Util
- _.isObject() Util
- _.isString() Util
- _.isValue() Util
- _.keys() Util
- _.mapObj() Util
- _.pad() Util
- _.parseDate() Util
- _.parseNumber() Util
- _.partial() Util
- _.promise()
- _.range()
- _.template() Util
- _.toString() Util
- _.trim() Util
- _.values() Util
- define() Web, Util
- promise.always()
- promise.error() Web, Util
- promise.fire()
- promise.stop()
- promise.then() Web
- require() Web, Util
- How to...