I need to clone the contents of a div and put it in the form of my modal

2

Good afternoon guys.

Again I turn to you about a problem I have. I need to use the syntax below in a modal.

$("#divConsulta").clone().appendTo($("#formFruta"));

In the line below when clicking, I open my modal with the data form to update:

<a href="<c:url value="edita?cod=${fruta.cod}"/>" class="btn btn-success btn-xs" data-toggle="modal" data-target="#update-modal" title="Editar"><span class="glyphicon glyphicon-edit"></span></a>

The problem is that I do not know how to do this:

  

clone (). appendTo

for my modal.

In short, I do not know if I'm correct, I need to pass the contents of a div that is on a page, that when the modal open button is clicked, the contents of #divConsulta go to the #formFruta that is in a modal Bootstrap.

I hope I've been clear because I've been trying for hours.

Thank you

    
asked by anonymous 16.12.2016 / 16:29

3 answers

1

The problem might be that when you try to insert the cloned content of the #divConsulta element, the modal content has not yet been inserted into DOM , and therefore the #formFruta element is not yet available for Javascript handling.

Try the events % of% or% of% of Boostrap:

$("#update-modal").on('show.bs.modal', function () {
    $("#divConsulta").clone().appendTo($("#formFruta"));
});

I hope I have helped.

    
16.12.2016 / 19:47
0

Take a look at this test I did, see if it helps: plunker

    
16.12.2016 / 18:19
0

I think the best way to do this is with append and not appendTo. You can use this:

var div = $("#divConsulta").clone();
$("#formFruta").append(div);

That way you're adding cloned content to the form.

    
16.12.2016 / 19:56