Native: Element

Custom Native to allow all of its methods to be used with any DOM element via the dollar function $.

Element Method: setStyle

Sets a CSS property to the Element.

Синтаксис:

myElement.setStyle(property, value);

Аргументы:

  1. property - (string) The property to set.
  2. value - (mixed) The value to which to set it. Numeric values of properties requiring a unit will automatically be appended with 'px'.

Возвращает:

  • (element) This element.

Пример:

//Both lines have the same effect.
$('myElement').setStyle('width', '300px'); //The width is now 300px.

$('myElement').setStyle('width', 300); //The width is now 300px.

:

  • All number values will automatically be rounded to the nearest whole number.

Element Method: getStyle

Returns the style of the Element given the property passed in.

Синтаксис:

var style = myElement.getStyle(property);

Аргументы:

  1. property - (string) The css style property you want to retrieve.

Возвращает:

  • (string) The style value.

Примеры:

$('myElement').getStyle('width'); //Returns "300px".
$('myElement').getStyle('width').toInt(); //Returns 300.

Element Method: setStyles

Applies a collection of styles to the Element.

Синтаксис:

myElement.setStyles(styles);

Аргументы:

  1. styles - (object) An object of property/value pairs for all the styles to apply.

Возвращает:

  • (element) This element.

Пример:

$('myElement').setStyles({
    border: '1px solid #000',
    width: 300,
    height: 400

});

Смотрите также:

Element Method: getStyles

Returns an object of styles of the Element for each argument passed in.

Синтаксис:

var styles = myElement.getStyles(property[, property2[, property3[, ...]]]);

Аргументы:

  1. properties - (strings) Any number of style properties.

Возвращает:

  • (object) An key/value object with the CSS styles as computed by the browser.

Примеры:

$('myElement').getStyles('width', 'height', 'padding');

//returns {width: "10px", height: "10px", padding: "10px 0px 10px 0px"}

Смотрите также:


Эта документация распостраняется на правах Attribution-NonCommercial-ShareAlike 3.0 License.
Оригинал документации на английском.
© Linux.ria.ua, 2008-2024