CSS Styles API
css.get()
Gets the inline CSS style values of the matched DOM elements.
- Accepts arguments as strings and arrays of strings.
You can pass inline CSS styles as individual arguments, as an array, or as a string separated by commas or spaces, using "kebab-case", "camelCase", or "snake_case" formats.
Each value is seen as a new argument. - Returns a string if a single argument and a single matched DOM element.
Returns an object if multiple arguments and a single matched DOM element.
Returns an array of strings if multiple arguments and a single matched DOM element.
Returns an array of objects if multiple arguments and multiple matched DOM elements.
If the inline CSS style value is missing, it will be null.
Example:
// <div style="background-color: red; margin: 10px">0</div>
// <div>1</div>
// <div>2</div>
$('div').css.get();
// {'background-color': 'red', 'margin-top': '10px', 'margin-right': '10px', 'margin-bottom': '10px', 'margin-left': '10px'}
$('div ? 1').css.get();
// null
$('div ? 1').css.get('margin');
// null
$('div').css.get('background-color');
// 'red'
$('div').css.get('margin');
// '10px'
$('div').css.get('margin-left');
// '10px'
$('div').css.get('background-color', 'margin');
// {'background-color': 'red', margin: '10px'}
$('div').css.get('background-color', 'margin-left');
// {'background-color': 'red', 'margin-left': '10px'}
$('div ?').css.get();
// [{'background-color': 'red', 'margin-top': '10px', 'margin-right': '10px', 'margin-bottom': '10px', 'margin-left': '10px'}, null, null]
$('div ?').css.get('background-color');
// ['red', null, null]
$('div ?').css.get('background-color', 'margin');
// [{'background-color': 'red', margin: '10px'}, {'background-color': null, margin: null}, {'background-color': null, margin: null}]
$('div ?').css.get('background-color', 'margin-left');
// [{'background-color': 'red', 'margin-left': '10px'}, {'background-color': null, 'margin-left': null}, {'background-color': null, 'margin-left': null}]
$('div').css.get('backgroundColor, margin-left');
// {backgroundColor: 'red', 'margin-left': '10px'}
$('div').css.get('background_color marginLeft');
// {background_color: 'red', marginLeft: '10px'}
$('div ?').css.get(['backgroundcolor', 'marginLeft']);
// {backgroundcolor: null, marginLeft: '10px'}