jQuery UI API -: data () Selector
category
Selector (Selectors) | the UI core (UI Core)
usage
Description: Select the data has been key elements in the specified storage.
jQuery( ":data(key)" )
参数 | 描述 |
---|---|
key | 数据的键。 |
Expression $( "div:data(foo)")
)") matched by a .data( "foo", value )
to store data div
.
Examples
Select elements with data, change their background color.
<! Doctype html> <Html lang = "en"> <Head> <Meta charset = "utf-8"> <Title>: data () Selector Examples </ title> <Link rel = "stylesheet" href = "// code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <Style> div { width: 100px; height: 100px; border: 1px solid # 000; float: left; } </ Style> <Script src = "// code.jquery.com/jquery-1.10.2.js"> </ script> <Script src = "// code.jquery.com/ui/1.10.4/jquery-ui.js"> </ script> </ Head> <Body> <Div id = "one"> </ div> <Div id = "two"> </ div> <Div id = "three"> </ div> <Script> $ ( "#one") .data ( "Color", "blue"); $ ( "#three") .data ( "Color", "green"); $ ( ": Data (color)") .each (function () { var element = $ (this); element.css ( "backgroundColor", element.data ( "color")); }); </ Script> </ Body> </ Html>