I have several lists that are sorted, and I can drag and drop items into each list.
The setup looks something like this:
<ul id="sortable1" class="connectedSortable"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> <ul id="sortable2" class="connectedSortable"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul>
JavaScript is simple and looks like this:
(following examples from jQuery)
<script> $(function() { $( "#sortable1, #sortable2" ).sortable({ connectWith: ".connectedSortable" }).disableSelection(); }); </script>
so far so good ...
Question:
For jQuery selector, can you use ul class instead of two list ids?
Sort of:
<script> $(function() { $( ".connectedSortable" ).sortable({ connectWith: ".connectedSortable" }).disableSelection(); }); </script>
Is it correct?
I tried this and it works ...
... but I wonder why the jQuery website provides an example with both list identifiers and a selector, not just a class name? Can I run into compatibility issues if I use the class as a selector?
The advantage of using a class name as a selector would be that I don't need to know the list identifiers in advance and theoretically create new lists on the fly?
What would be the best practice and kind of โmistakeโ?
Thanks a lot!
source share