sortable list of todo items in javascript

One way to create a sortable list of todo items in javascript is by using the jQuery UI Sortable plugin. Here is an example implementation:

HTML:

<ul id="sortable">
  <li>Task 1</li>
  <li>Task 2</li>
  <li>Task 3</li>
</ul>
79 chars
6 lines

CSS:

#sortable {
  list-style-type: none;
  margin: 0;
  padding: 0;
}
66 chars
6 lines

JavaScript:

index.tsx
$( function() {
  $( "#sortable" ).sortable();
  $( "#sortable" ).disableSelection();
});
90 chars
5 lines

In this example, we first select the <ul> element using jQuery and call the sortable() method to make it sortable. We also call the disableSelection() method to prevent text from being selected while dragging.

After implementing this code, users will be able to drag and drop tasks to rearrange their order on the list.

gistlibby LogSnag