Reputation: 1921
For my webpage, I have a number of lists which I'm generating dynamically from the database. Each list is generated like so:
<ul id = "<%= "subgroups_for_tumourgroup_" + item.ID %>">
I'm trying to make them sortable using jquery's sortable list
<script type="text/javascript">
$(function() {
$('#subgroups_for_tumourgroup_1').sortable();
});
</script>
The question is, given that I may have any number of IDs (the "1" in the code above is the ID) and they may not even be sequential (I may have lists called "subgroups_for_tumourgroup_1", and "subgroups_for_tumourgroup_3", but no "subgroups_for_tumourgroup_2", how do I make all those lists independantly sortable?
Upvotes: 1
Views: 883
Reputation: 342635
You can use Attribute Starts With Selector to match all IDs up to the point right before the number that gives them their uniqueness:
// make all ULs whose id starts with 'subgroups_for_tumourgroup_' into sortables
$('ul[id^=subgroups_for_tumourgroup_]').sortable();
That said, can't you just use a class selector instead, and not have to bother with IDs?
$("ul.sortable").sortable();
Upvotes: 4