, , . @BalusC, jQuery val() (, , , ). , div, span .., value, , jQuery . , ul li:
<ul id="tireBrands">
<li value="Yokohama">Yokohama</li>
<li value="Michelin">Michelin</li>
<li value="Continental">Continental</li>
<li value="Dunlop">Dunlop</li>
</ul>
$('#tireBrands li').click(function(){
alert($(this).val());
alert($(this).attr('value'));
});
, value. , val() - . 0 . attr('attributename') ? -, , , jquery , value, 0. html :
<ul id="tireBrands">
<li value1="Yokohama">Yokohama</li>
<li value1="Michelin">Michelin</li>
<li value1="Continental">Continental</li>
<li value1="Dunlop">Dunlop</li>
</ul>
value1, .
$('#tireBrands li').click(function(){
alert($(this).val());
alert($(this).attr('value1'));
});
, :
<ul id="tireBrands">
<li value="1">Yokohama</li>
<li value="2">Michelin</li>
<li value="3">Continental</li>
<li value="4">Dunlop</li>
</ul>
, :
$('#tireBrands li').click(function(){
alert($(this).val());//case 1: Will alert 1 or 2 or 3 or 4;
alert($(this).attr('value'));//case 2: Will also alert 1 or 2 or 3 or 4;
});
The difference between the last and previous 2 html is that in the latter the attribute value valueis a numerical value, and in the previous ones, an alphanumeric value. For some reason, jQuery is fine when the user attribute valuehas a numerical value and behaves as if it were dealing with an input type element. I felt a little lazy to find out the reason for this. So if you're interested, check out the jquery source code. Good script.