Skip to content

Instantly share code, notes, and snippets.

@hustKiwi
Created June 15, 2012 07:52
Show Gist options
  • Save hustKiwi/2935277 to your computer and use it in GitHub Desktop.
Save hustKiwi/2935277 to your computer and use it in GitHub Desktop.
function createListView(id) {
var listView = $('<div>').addClass('list').click(function(e) {
var $this = $(this),
$target = $(e.target);
if ($(e).is('li')) {
$(e.target).addClass('selected');
}
$.data($this, 'selected', $target.text());
}).keypress(function(e) {
if (e.keyCode === 8) {
$(this).find('.selected').remove();
}
});
return listView;
}
var listView = createListView();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment