tags:

views:

38

answers:

1

I'm using JQuery to drag items from one list and drop them onto another.

Once the item is dropped it is removed from its original list and appended to its destination list.

I've used the code below and it seems to perform perfectly fine when inspecting the DOM, however it displays incorrectly on the page. Usually outside of the list and to the top right.

My first guess is that this was a CSS issue, however the problem persists even after removing all stylesheets.

Closer inspection in the Chrome inspector reveals that an inline style is added to each list item.I'm not sure where its coming from.

Here's my code.

        $(function() {

    $( ".drag" ).draggable();

    $( ".drop" ).each(function (index){

        var title = $(this).attr('title');

        $(this).droppable({      
           accept:  title,
           activeClass: "ui-state-hover",
           hoverClass: "ui-state-active",
           drop: function( event, ui ) {

           ui.draggable.remove();
           $(this).append(ui.draggable);
           }
          }); 
    });
 });
</script>




<ul>
<li class="drag RED">RED</li>
<li class="drag BLUE">BLUE</li>
</ul>

<ul class="drop" title=".RED">
<li>Stuff</li>  
</ul>

<ul class="drop" title=".BLUE">
<li>Stuff</li>      
</ul>
A: 

Do you mean style like

position: relative; left: 151px; top: 32px;

if so, this is from jquery UI plugin, which tell where is your droped element, relative to parent.

JapanPro
what's wrong with `title=".RED"` ?
Reigel
@JapanPro I don't think this is the problem. I have no styles defined. I modified the script to remove all titles and classes however the position problem remains.
matt
@matt dont you have style for RED,BLUE
JapanPro
@JapanPro - `My first guess is that this was a CSS issue, however the problem persists even after removing all stylesheets.` , clearly from the OP :)
Reigel
@Reigel there is nothing wrong with that , only i m saying , if further element is created in drop area using the class name.
JapanPro