admin管理员组文章数量:1431426
I am looking for an alternative to using an object/variable in global scope -- I would like to associate key/value pairs with specific DOM elements (eg, a DIV), so that I can use them as input for logic that processes other elements (eg, child elements of said DIV).
I tried something naive like: $('[foo=bar]').key='value' , and $('[foo=bar]')[key]='value', but it puked.
Doing something like: var foobar = $('[foo=bar]'); foobar.key = 'value' -- works, but the new property/value only affects the new object (ie, foobar, not $('[foo=bar]'))
Most likely there's something terribly basic I am overlooking. Any help is appreciated, thanks!
I am looking for an alternative to using an object/variable in global scope -- I would like to associate key/value pairs with specific DOM elements (eg, a DIV), so that I can use them as input for logic that processes other elements (eg, child elements of said DIV).
I tried something naive like: $('[foo=bar]').key='value' , and $('[foo=bar]')[key]='value', but it puked.
Doing something like: var foobar = $('[foo=bar]'); foobar.key = 'value' -- works, but the new property/value only affects the new object (ie, foobar, not $('[foo=bar]'))
Most likely there's something terribly basic I am overlooking. Any help is appreciated, thanks!
Share Improve this question asked Mar 9, 2010 at 0:00 btkbtk 3,2352 gold badges31 silver badges30 bronze badges2 Answers
Reset to default 5$().data()
is what you seek
Here is a link to .data()
in the API Documentation for jQuery.
Description: Store arbitrary data associated with the matched elements.
本文标签:
版权声明:本文标题:is there a way to add a variableproperty to a DOM element (eg, an element returned by a jQuery selector) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745483367a2660274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论