Load content from one div into another div

Asked

Viewed 3,455 times

2

I have the following problem. How do I load a content from a div into another div empty that is in the same HTML file?

Example:

<div class="conteudo">
   <label> Teste 1 </label>
   <label> Teste 1 </label>
</div>
<div class="receber conteudo">

</div>

I wanted to play all this content from the first div into the second div empty through a jQuery function, already tried the method find but without success.

  • If you are using ajax? e for image upload have an example between http://www.loading.io

  • @Kingrider doesn’t need Ajax, he just wants both label are copied to the second div. Certo Marlon?

  • That’s right @Kingrider, I need to upload all content from an existing form inside an empty div..

  • Allan’s answer answers your question?

1 answer

4


In their example, the two divs contained the class .conteudo.

In order to avoid class name conflict, I changed the class name in the div that receives the content: from receber conteudo for receber_conteudo.

See below the working example:

//
// JAVASCRIPT
//

$('#btnMoverConteudo').click(function(){
  // copia o conteúdo em .receber_conteudo
  $('.receber_conteudo').append($('.conteudo').html()); 
  // limpa o valor de conteúdo
  $('.conteudo').html(''); 
});
//
// CSS
//

.receber_conteudo{
    border:1px solid red;
    padding:15px;
 }

.conteudo{
    border:1px solid black;
    padding:15px;
 }
//
// HTML
//

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="conteudo">
   <label> Teste 1 </label>
   <label> Teste 1 </label>
</div>
<div class="receber_conteudo">

</div>
<input type="button" id="btnMoverConteudo" value="Mover"/>

  • That’s right. Thank you very much Allan Andrade, problem solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.