开发者

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-

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜