YouTip LogoYouTip

Api Data Selector

# jQuery UI API - :data() Selector ## Category (#) | (#) ## Usage **Description:** Selects elements where data is stored under the specified key. jQuery( ":data(key)" ) | Parameter | Description | | --- | --- | | key | The key for the data. | The expression `$( "div:data(foo)")` matches a `div` that has data stored via `.data( "foo", value )`. ## Example Select elements with data and change their background color. :data() Selector Example div { width: 100px; height: 100px; border: 1px solid #000; float: left; }
$( "#one" ).data( "color", "blue" ); $( "#three" ).data( "color", "green" ); $( ":data(color)" ).each(function() { var element = $( this ); element.css( "backgroundColor", element.data( "color" ) );}); (#)
← Api Focusable SelectorApi Zindex β†’