I have the one div
with the id
Branches and apart from that I have another div
empty one with the id
selected ones, what I need is to pass with a click to the button pasar
all the div
contents in Sucursales
aseleccionadas
$("#pasar").click(function(){
// ?????????
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="Sucursales">
<div class="Sucursal">sucursal 1</div>
<div class="Sucursal">sucursal 2</div>
<div class="Sucursal">sucursal 3</div>
</div>
<div id="Seleccionadas">
</div>
<button id="Pasar"></button>
The first thing is to select the divs that interest us, for example all the class items
.Sucursal
, or if you prefer all the divs that are direct children of#Sucursales
.And then they just need to be added to the target container with appendTo() :
However, if we also want them to keep all of their associated events, detach() must be called first :
Code
It occurs to me that you could detach() all the elements of the .branch class and then attach them to the #selected element, something like that?
All the answers above work, but you probably want to use a button for each and not a button to add all the options.
To do this you have to identify the value of the button you are pressing, which element it refers to.
It could also be the case that you want to add all the elements, but it would be controlled through the checkbox, to decide which and which ones you do not want to add, if so, consult it again and I will tell you how to do it.
Hello, I do have a similar query... I hope you can help me. two
It works perfectly but the only problem I have found is that when moving the screen in a mobile resolution the Drag and drop is useless or it is super uncomfortable. And trying to implement the last example that you provided, the only thing that fails me is that it has a fixed class anchored, when in my project they are all the same and I do not need to differentiate them, so I would only need a button that sends them to the class without further ado.
Attached link since I had it laid out in codepen for a long time, I hope it is not a problem. Example