Question

Im trying to create a page in which users can search for items on the left side of the page, and drag and drop the items they want onto the right, kind of like a shopping cart.

I have been using

 $(function() {
 $(".result").draggable({
    helper: function(event, ui) {
    return $(this).clone().children("img");
    }
    });

    $("#rightcol").droppable({
        accept: ".result",
        drop: function(event,ui){
        $(this).append($(ui.draggable).clone());
        //console.log($(ui.draggable));
        }
        });

});

for the drag & drop which works how I was hoping for, but whatever the user drags onto the the right side (#rightcol) is lost when a new search is submitted. I have tried changing the form submit to use ajax with jquery like this

 $(document).ready(function() {
          $("#form").submit( function () {    
          $.post(
           'p_search.php',
            $(this).serialize(),
          function(data){
              //data is what i want to be draggable
              //call other function here
              $(".build").html(data).load();
            }
          );
          return false;   
        });   

 });

Which works great, but the divs(.result) are not draggable. Is there a way to easily initialize the (.result) elements without refreshing the page?

Was it helpful?

Solution

I believe they're not draggable because they were created after you've defined which items are draggable.
(meaning - they're created after the $(".result").draggable(... call.)
I think you should take a look at live()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top