Well, some will suggest me to use cloneNode(true)
of Javascript to make a appendChild(var)
in the DOM .
But for this case, I already used this native feature, but it did not meet my need. Why, when I make a faithful clone of your child in the DOM, the CSS that should stylize all its elements is lost, does not define anything.
So I believe that retrieving your attributes with the for
loop is ideal for replicating the elements again. Here's what I've tried:
var str = document.getElementById('nome').value;
if (document.getElementsByClassName(str)) {
document.getElementById('B').innerHTML = '';
var figura = document.body.getElementsByTagName('img');
var evento = document.body.getElementsByTagName('a');
for (var i in figura, evento) {
var image = figura[i];
var titulo = image.className;
var endereco = image.src;
var clic = evento[i];
var link = clic.href;
if ((titulo == str) || (clic == this.link)) {
var xerox = image.innerHTML;
var copia = endereco.innerHTML;
var clique = link.innerHTML;
document.getElementById('B').innerHTML = '<p><a href="'+ clique +'"><img src="'+ copia +'" class="'+ xerox +'"></a></p>';
}
}
}
#A {
float : right;
width : 115px;
height : 400px;
overflow: auto;
padding : 10px;
border : thin solid silver;
}
#B {
overflow-x: auto;
overflow-y: hidden;
width : 400px;
height : 100px;
padding : 10px;
border : thin solid silver;
}
#B p {
padding : 10px;
margin : 0 auto;
cursor : pointer;
display : inline-blinkk;
display : inline;
vertical-align : top;
}
<div id="A">
<p><a href="http://www.monkie.com.br" onclick="return false"><img src="https://lorempixel.com/100/100/people/a/"class="foto"></a></p>
<p><a href="http://www.monkie.com.br" onclick="return false"><img src="https://lorempixel.com/100/100/people/b"class="foto"></a></p>
<p><a href="http://www.monkie.com.br" onclick="return false"><img src="https://lorempixel.com/100/100/people/c"></a></p><p><ahref="http://www.monkie.com.br" onclick="return false"><img src="https://lorempixel.com/100/100/people/d"></a></p><p><ahref="http://www.monkie.com.br" onclick="return false"><img src="https://lorempixel.com/100/100/people/e"class="foto"></a></p>
</div>
<div id="B" nowrap></div>
<input type="hidden" id="nome" value="foto"/>
The detail is to replicate only the className
whose value (photo) is defined in this input type='hidden' id='nome'
put in the example.
The div id="A"
is vertical, it symbolizes a playlist in the actual project, and already div id="B"
, is horizontally aligned to the left where it symbolizes related elements when chosen by clicking on the playlist. Both have different roles, different CSS rules.
So the question. I can not reuse the CSS from div id="A"
to div id="B"
.