1
I have an image and a div conteudo-img.
When clicking on the image it has to be copied to the div conteudo-img, what methods I can use to make this copy and which one is most viable via Javascript.
#images{
float:left;
}
#conteudo-img{
width: 300px;
height: 300px;
border: 1px solid #f1f;
float: left;
}
<html>
<body>
<div id="images">
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
</div>
<div id="conteudo-img"> </div>
</body>
</html>
#images{
float:left;
}
#conteudo-img{
width: 300px;
height: 300px;
border: 1px solid #f1f;
float: left;
}
<div id="random_id">
<div class="img">
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
</div>
<div class="img">
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
</div>
<div class="img">
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
</div>
<div class="img">
<img src="https://orig00.deviantart.net/d61c/f/2015/256/c/7/dipper_ice_cream_splat_icon___free_to_use_by_icelemontea83-d99f4z7.gif"><br>
</div>
</div>
<div id="conteudo-img"> </div>
What would this be
const? It’s like defining a variable?– Sora
@You can read more about it here: https://answall.com/a/206121/129
– Sergio
Instead of passing the id of the div as parameter, I can also pass the class for example??
– Sora
@Sora depends. If there is only one element you can use
.querySelector('nomeDaClasse'). If you have multiple elements with that class you have to iterate. Displays the HTML case you have that I can give an example.– Sergio
I changed my question and made a new code where it requires the class name as parameter
– Sora
@Sora my answer is still valid if you want to copy only the
img. Or do you want to copy thedivaround the img?– Sergio
Only the img, I thought it was not valid because of this line:
const images = document.getElementById('images');However tested and worked, I will mark your reply as valid soon Thanks @Sergio !!– Sora