You can do this, use data-
attributes though (part of the HTML5 specification), like this:
<li data-something="CommonLi"></li>
jQuery even has built-in support for these in 1.4.3+, for example:
$("li").data("something") //"CommonLi"
For your other questions:
if you're planning to have several attribute I suggest to set a unique namespaced attribute, e.g.
<li data-yourapp>...</li>
and use that attribute like an hashtable
$("li").data("yourapp", {
points : 2000,
life : 1,
weapons : {
firegun : 0,
missiles : 12
}
});
in this way you will reduce element access and you will retrieve all custom data once
I would personally recommend you to using jquery builtin method for saving data with each element. following is the code snippet for saving data:
$("ul").data("CommonUl");
$("li").data("CommonLi");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With