0

I am appending elements/ texts into the body part of the html using jQuery. And I am using appendTo method to append the content into the div but it is always append at the last not where I want to drop it .

Please let me know which method I can use to achieve that.

I am implementing a mail body functionality where I can write anything and drop any text anywhere in between that .

Please suggest.

JQuery version 3+

Code snippet:

<div class="row">
    <div class="col-sm-4">
        <div class="draggable">
            <p>Name</p>
            <p>Lastname</p>
            <p>Age</p>
            <p>City</p>
        </div>
    </div>
    <div class="col-sm-8">
        <h4>Droppable Area</h4>
        <div id="contentarea" contenteditable="true" style="width:100%; height: 200px">

        </div>
    </div>
</div>
<script type="text/javascript">
$(document).ready(function() {
    $( ".draggable" ).draggable({ 
        revert: "invalid",
        stack: ".draggable",
        appendTo: 'body',
        //scroll: false,
        helper: 'clone',
        start: function(e, ui)
             {
              $(ui.helper).addClass("ui_atdrag_custom_class");
             },

             stop: function(e, ui)
             {
              $(ui.helper).removeClass("ui_atdrag_custom_class");
             },

    });
    $( "#contentarea" ).droppable({
         accept: ".draggable",
         tolerance: "touch",
        drop: function( event, ui ) {

              var droppable = $(this);
              var draggable = ui.draggable;
              draggable.clone().appendTo(droppable);
            //$(this).find("p").addClass( "ui_dropped_content");
        }
    });

});

Any fiddle would be more helpful.but should be drop wherever I want to drop the text / link .

0 Answers0