jQuery jQuery.cssHooks method
Example
Define a new CSS hook
$
(
function
(
$
)
{
//
First check whether the jQuery version supports cssHooks
if
(
!$.
cssHooks
)
{
//
If not supported, output an error message
throw
(
new
Error
(
"
This feature requires jQuery version 1.4.3 or greater
"
)
)
;
}
//
Wrap it in the DOM document-ready event; write the cssHooks at this point to avoid the cssHooks being overwritten elsewhere
$
(
function
(
)
{
$.
cssHooks
.
height
=
{
get
:
function
(
elem
,
computed
,
extra
)
{
//
Handle getting this CSS property
}
,
set
:
function
(
elem
,
value
)
{
//
Handle setting the CSS property
alert
(
'
Execute the processing
'
)
;
}
}
; $
(
'
body
'
)
.
css
(
'
height
'
,
'
100%
'
)
;
}
)
;
}
)
(
jQuery
)
Try it »
Definition and Usage
$.cssHooks provides a way to get and set specific CSS values by defining functions.
**Note:** 1. Its purpose is to standardize CSS property names or create custom properties.
2. For example, some versions of WebKit-based browsers require the -webkit-border-radius property to set an element's border-radius, while early Firefox versions use the -moz-border-radius property. A CSS hook can standardize these prefixed properties so that .css() accepts a single, standard property name (border-radius, or borderRadius using DOM property syntax).
Syntax
$
.cssHooks
More examples
Testing browser vendor-prefix variants
Before standardizing vendor-specific CSS properties, first determine whether the browser supports the standard property or a variant with a browser vendor prefix.
Define a complete CSS hook
Defines a complete CSS hook.
jQuery HTML/CSS methods