简体   繁体   中英

Get the elements id already in the droppable div

I know there are lots of questions somewhat related to this, but as I am new to jQuery html, Can't figure out how to do this.

I have a div container(which has already some elements(div) inside it) and I am dropping other divs inside it.

What I want to know is all the divs ID already present in the container at the time of dropping.

What I am adding is a same types of items from a group to the container, Now if I am adding the same item twice I need to know how many same type of items are already present in the container, so I can create its ID as car1,ca2,car3 etc.

I know its a bit confusing, feel free to say, if I can make you understand.

Thanks.

I know there are lots of questions somewhat related to this, but as I am new to jQuery html, can't figure out how to do this.

I have a div container(which has already some elements(div) inside it) and I am dropping other divs inside it.

What I want to know is all the divs ID already present in the container at the time of dropping.

What I am adding is a same types of items from a group to the container, Now if I am adding the same item twice I need to know how many same type of items are already present in the container, so I can create its ID as car1,ca2,car3 etc.

I know its a bit confusing, feel free to say, if I can make you understand.

Thanks.

  $( "#c1 .component-group" )
    .droppable({ activeClass: "ui-state-default",
                 hoverClass: "ui-state-hover",
                 accept: ":not(.ui-sortable-helper)",
                 drop: function( event, ui ) {
                     var draggedImage = ui.draggable.find("img").attr("src");
                     var draggableAdded;

                     for (i =0 to elements in c1 )
                     {
                         if(element dragged == element present )
                            get the id 
                            new_id = id + 1
                            make a new div with new_id and append with the container.
                         }

                         $(event.target).append(draggableAdded);
                     }
           });

如果我了解您的要求,就可以解决这个问题:

ui.draggable.("#c1 .component-group").serialize()

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