Custom css styles
Is it possible to store custom attributes in css settings?
Suppose I want to store some metadata like:
.some_class {
customAttribute: "metadata value";
}
And then retrieve this metadata using jquery:
alert($("div.some_class").css("customattribute"));
// Outputs message "me开发者_JAVA技巧tadata value"
Use jQuery's .data()
.
Example:
$('.elem').data('customattr', 'value');
And retrieve it using:
$('.elem').data('customattr');
Or if you want to store it in the HTML.
Use HTML5's data attr:
<div class="elem" data-customattr="value">
HTML5's custom attributes always start with data-
精彩评论