Reputation: 167
How to make this sortable work for multi divs with the same class name #sortable.
here is an example
update
<div class="multi-fields" id="sortable">
//something
</div>
<div class="multi-fields" id="sortable">
//another something
</div>
sortable
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
jQuery(document).ready(function($) {
$("#sortable").sortable({
cursor:'move',
opacity: 0.5,
cursor: 'pointer',
axis: 'y',
update:function(event, ui){
var order = $('#sortable').sortable('serialize');
$.ajax({
type: "POST",
url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
data: "action=update_field_order&" + order
});
}});
$("#sortable").disableSelection();
});
</script>
Upvotes: 0
Views: 589
Reputation:
I think you might be saying this:
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
jQuery(document).ready(function($) {
$(".sortable").sortable({
cursor:'move',
opacity: 0.5,
cursor: 'pointer',
axis: 'y',
update:function(event, ui){
var order = $('.sortable').sortable('serialize');
$.ajax({
type: "POST",
url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
data: "action=update_field_order&" + order
});
}});
$(".sortable").disableSelection();
});
</script>
Change also the id attribute to class and try!
Upvotes: 0
Reputation: 1210
$("#sortable")
will select all tags with id equals to "sortable", NOT classes. .sortable
?$(".sortable")
. Does it work now?EDIT To be exact, (3) IS valid in HTML5. Still a better practice is to start your class / id names with a letter. In case you have to go with '#' you will have to escape it in the jQ selector. This is unnecessary confusion.
Upvotes: 1