Reputation: 7971
I have string value in li
's value attributes but it is giving me 0 when I am trying to get with jquery. Any Idea why? fiddle
$(function(){
alert($('li').attr('value'))
})
<li value="CAD"></li>
Upvotes: 1
Views: 351
Reputation: 205
try this one fiddle
<li data-value="CAD"></li>
alert($('li').data('value'))
Upvotes: 0
Reputation: 38598
For custom properties you could use $.data()
method, for sample:
alert($('li').data('value'));
and in your html
use the prefix data-
,
<li data-value="CAD"></li>
You also could use $.data()
method to set values in a data custom property, for sample:
$('li').data('value', '123');
Upvotes: 2
Reputation: 819
In html value is a predefined attribute for li which can store only number. you can find it here. As it can be used to store number of the list.
http://www.w3schools.com/tags/tag_li.asp
Upvotes: 1
Reputation: 1317
You can try following..
Html:
<li data-value="CAD"></li>
JS:
alert($('li').data('value'));
Here is demo : http://jsfiddle.net/ed8ZL/
Upvotes: 1
Reputation: 2364
You can use data-
prefix.
$(function(){
alert($('li').attr('data-value'))
})
<li data-value="CAD"></li>
Upvotes: 1