0

I am trying to add the following function to a Sortable group of divs. I would like to have a button (could be anything really) in each div which when clicked will place it in the first position of the group.

<div id="sortable" class="content">
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 1</span></div>
        This is div 1.
        <br/><input type="button" name="button1" id="button1" value="Make me First"/>
    </div>
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 2</span></div>
        This is div 2.
        <br/><input type="button" name="button2" id="button2" value="Make me First"/>
    </div>
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 3</span></div>
        This is div 3.
        <br/><input type="button" name="button3" id="button3" value="Make me First"/>
    </div>
    <div class="tile">
        <div class="tile_header"><span class="header_text">Header 4</span></div>
        This is div 4.
        <br/><input type="button" name="button4" id="button4" value="Make me First"/>
    </div>
</div>

These are the divs.

$(function() {  
    $( "#sortable" ).sortable({ 
        handle:".tile_header",
        revert:true
    });  
});  

This is my call to sortable.

I have created a jsFiddle showing what I mean. I've tried to look up if it is possible but didn't find anything similar.

Any ideas?

4

2 回答 2

3
 $(function () {      
    $("input:button").click(function () {
        $(this).parents(".tile").prependTo("#sortable");
    });
 });

http://jsfiddle.net/GrDBW/2/

于 2013-09-23T08:45:53.577 回答
0

我认为这不是您的代码正常工作的正确标记。

我正在阅读 jquery sortable() API 文档,从我所读到的内容中,您必须在列表中提供元素,即使您想将其显示为网格。

http://jqueryui.com/sortable/#display-grid

于 2013-09-23T08:57:08.387 回答