How do I copy the value of a DIV to another DIV with Javascript?

0

My problem is this:

I have a page in html, and on this page, it has 2 divs. in the second div, I have a javascript that stores a value in a given variable.

What I want is to display the value of this variable in the first div.

Do you know how I can do this?

    
asked by anonymous 07.07.2016 / 16:58

1 answer

2

To create in Pure JavaScript just follow this example:

// Elemento com o Texto
var elemento = document.getElementById('teste').innerHTML;
// Escrevendo em outro Elemento
var texto = document.getElementById('texto');
texto.innerHTML = "Texto Copiado: " + elemento;
<div id="teste">
  Exemplo
</div>
<div id="texto"></div>

But if it's in jQuery just follow the example of @ Adriano-Resende:

// Elemento com o Texto
var elemento = $('#teste').html();
// Escrevendo em outro Elemento
var texto = $('#texto');
texto.html('Texto Copiado: ' + elemento);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><divid="teste">
  Texto
</div>
<div id="texto"></div>
    
07.07.2016 / 19:42