I'm trying to adapt this code to my li lists.
[
I sketched something that shows the exact logic.
Clicked element goes first!
Second element clicked goes first but the preview cliched goes last.
This is the code:
$('ul li').each(function() {
var $this = $(this).data({
position: $(this).index()
}),
$table = $this.closest('ul'),
$input = $this.find('input');
$input.bind('click', function(e) {
var $first = $table.find('li:first'),
position;
if ($(this).is(':checked')) {
position = $first.data('position');
$table.find('li input').not($(this)).removeAttr('checked');
if (position != 0) $first.insertAfter($table.find('li').eq(position));
$this.prependTo($table);
} else if ($this.data('position') != 0) {
position = $this.data('position');
$this.insertAfter($table.find('li').eq(position));
}
});
});
I have the code below that works with tables but I'd like to implement this on a ul li. Is there a way to make the checkbox input becoming a li or a anchor tag?