Below I have this little list:
<ul id="selectable">
<li id='0'></li>
<li id='1'></li>
<li id='2'></li>
<li id='3'></li>
<li id='4'></li>
</ul>
<span>You've selected:</span>
<span id="select-result">none</span>.
Combined with jQuery, It should get the id
of the selected element:
<script>
$(function() {
$( "#selectable" ).selectable({
stop: function() {
var result = $( "#select-result" ).empty();
$( ".ui-selected", this ).each(function() {
var index = $( "#selectable li" ).attr( 'id' );
result.append( index );
});
}
});
});
</script>
Every time, I click an element, it displays: 0
Why? When I click an list-element the second time, it should display: 1
etc, What did I do wrong?