简体   繁体   English

jQuery DataTables将div附加到特定位置

[英]jQuery DataTables append div to specific place

I have code: 我有代码:

<div class="addButton col-lg-6">
    <button type="button" class="btn btn-primary" data-toggle="modal">BTN</button>
</div>
<div class="table-responsive">
    <div id="PositionDataTable2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
        <div id="PositionDataTable2_processing" class="dataTables_processing" style="display: none;">Processing...</div>
        // place where <div class="addButton"> should appear
        <div id="PositionDataTable2_filter" class="dataTables_filter"></div>
        <div class="dataTables_paginate paging_simple_numbers" id="PositionDataTable2_paginate"></div>
    </div>
</div>

I want to take first div, which has addButton class and put into div PositionDataTable2 and place it between the processing and filter parts. 我想先使用div,它具有addButton类,并放入div PositionDataTable2,并将其放在处理和过滤器部件之间。 But append and prepend only does it inside div start or end. 但是追加和前置仅在div开始或结束内执行。

Also it would be great, if someone would suggest how to place it correctly and make a copy or so that my button wouldn't disappear on datatable fndestroy and recreate. 如果有人建议如何正确放置它并进行复制,或者使我的按钮不会在数据表数据库上消失并重新创建,那也很好。

您可以尝试使用$.after()插入,例如:

$(".dataTables_processing").after($(".addButton").html());

Jquerys insertAfter() should work. jQuery insertAfter()应该可以工作。 Try something like this: 尝试这样的事情:

$('div.addButton').insertAfter('div#PositionDataTable2_wrapper');

EDIT: If you don't want that the first addButton disappears you could use .clone() 编辑:如果您不希望第一个addButton消失,则可以使用.clone()

$('div.addButton').clone().insertAfter('div#PositionDataTable2_wrapper');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM