0
I want to copy the div
clicked, into the form
which already contains the select
.
For example this:
var opt = document;
function processar(el) {
opt.getElementById('minhaLista').innerHTML = el;
}
<form name="form" id="minhaLista">
<select>
<option value="">A</option>
<option value="">B</option>
<option value="">C</option>
</select>
</form>
<hr size="1">
<div id="vitrine">
<div id="produto1">
<a href="javascript:void(0)" onclick="processar(produto1)">
<img src="https://sites.google.com/site/mplayerplugin/repositorio/procurando_dory.jpg" width="300" />
</a>
<div>
A
<p>Exemplo 1</p>
<span>1</span>
</div>
</div>
<hr size="1">
<div id="produto2">
<a href="javascript:void(0)" onclick="processar(produto2)">
<img src="https://sites.google.com/site/mplayerplugin/repositorio/big_buck_bunny.jpg" width="300" />
</a>
<div>
B
<p>Exemplo 2</p>
<span>2</span>
</div>
</div>
<hr size="1">
<div id="produto3">
<a href="javascript:void(0)" onclick="processar(produto3)">
<img src="https://sites.google.com/site/mplayerplugin/repositorio/animais_cantando.jpg" width="300" />
</a>
<div>
C
<p>Exemplo 3</p>
<span>3</span>
</div>
</div>
</div>
The main focus is the image element [img
], paragraph [p
] and text [span
].
The select
must remain within the form
, without removal by script.
Perhaps the correct term is to perform a replica of div
to the form
.
However simple it may seem, unfortunately I could not.
Use the property
outerHTML
, for ex:opt.getElementById('minhaLista').innerHTML = el.outerHTML;
– Valdeir Psr
The
el
is an object, so you can’t add it withinnerHTML
(unless you useouterHTML
orinnerHTML
on the object to be replicated).select
, you can add adiv
within theform
and, instead of usingopt.getElementById('minhaLista')
, you useopt.getElementById('minhaLista_minha_div').innerHTML = el.outerHTML;
– Valdeir Psr
https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML
– Valdeir Psr
@Valdeirpsr Grateful for the good will and explanation as well as the link that points me.
– Diego Henrique
Check this: https://codepen.io/valdeir2000/pen/MXaEpo
– Valdeir Psr