1
How to move the contents of a div to another div and maintain the status of the elements?
Example: move a input of a div to another, without creating a new input and delete the old one, as in the code below, thus keeping the value typed in the input `.
This code is just a basic example of what I’m trying to do, there’s nothing "fancy".
I could take the value of
inputold and put it in the newinput, but I’m using theinputas an example could be any other element.
window.onload = function(){document.getElementsByTagName("input")[0].value="Valor do input";};
function mover(){
origem = document.getElementById("origem");
destino = document.getElementById("destino");
destino.innerHTML = origem.innerHTML;
origem.innerHTML="";
}
<div style="background:green" id="origem"><input id="input"></div>
<div style="background:red" id="destino"></div>
<button onclick="mover()">MOVER</button>
Like I said in the question
Como mover o conteúdo de uma div, there may be more than one element, the way you presented I would have to select each element individually, it would not be feasible. So I usedinnerHTMLto take everything inside thediv– Mark Vaaz
@Markvaaz, I updated the response.
– Victor Carnaval