user1638466
user1638466

Reputation: 310

issue with html li tag

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

Answers (3)

Baskar
Baskar

Reputation: 1140

Try .append in jquery if u want to add attribute dynamically

Upvotes: 0

Sushanth --
Sushanth --

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

James Allardice
James Allardice

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

Related Questions