简体   繁体   中英

how to get index position of a droppable div in jquery

I am using drag and drop functionality. I want index position of a div which is dropped something like 1 ,2,3...after each drop.

I used .position() and .offset() method but it gives me top and left index position in px my code is

$(".workArea").droppable({
drop: function( event, ui ) {
var y = ui.position.left();
var z = ui.position.top();

Please help in getting index position like 1,2 ,3 after each drop

Try this:

 drop: function(event, ui) {

        alert($(event.target).index());

    }

Working demo: http://jsfiddle.net/Fep8h/

check this :)

 var postionA = value1;
 var postionB = value2;
$("#div").droppable({
   drop: function( event, resp ) {
      console.log(resp.positionA,resp.positionB,resp.target);
   }
});

The code below gives the index value every time 5.

drop: function(event, ui) {
   alert($(event.target).index());
}

my code is following

$("#sortable").droppable({
       helper: "clone",
       drop: function (event, ui) {
          alert($(ui.placeholder).index());
       }
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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