Reputation: 310
Is it possible to add an attribute to html list elements (li)?
I need to have another attribute, I already used both value and html attributes.
Is there a way to fix it?
Maybe with jquery
Upvotes: 0
Views: 107
Reputation: 55740
you can use data attributes from HTML5
<li data-val="yourvalue" />
To access it you just do this
$('li').attr('data-val') ; OR $('li').data('val') ;
Your can specify any name to your attribute..
Upvotes: 2
Reputation: 165941
Assuming I've understood your question correctly, you can use HTML5 data-*
attributes to add arbitrary data to any element:
<li data-something="randomvalue">
Since you've tagged your question with jQuery, you can use the .data()
method to get the value of a data-*
attribute. Without jQuery, the best way is to use the usual getAttribute
method.
Upvotes: 4