2
I have a div where multiple are added fieldsets and just below a hr:
The content of div is dynamic and may have 3 or more fieldsets. In my code I could only get the contents inside the first. How can I take the whole fieldset?
Here’s the code from my page:
<html>
<head><title></title></head>
<body>
<h3>Multiplos Fieldsets</h3>
<br>
<div id="BlocosDinamicos">
<fieldset><legend></legend>
<p>Conteudo 1</p>
</fieldset>
<fieldset><legend></legend>
<p>Conteudo 2</p>
</fieldset>
<fieldset><legend></legend>
<p>Conteudo 3</p>
</fieldset>
</div>
<hr />
<div id="CopiaUltimoConteudo"></div>
</body>
</html>
And here the script:
document.getElementById("CopiaUltimoConteudo").innerHTML =
document.getElementById("BlocosDinamicos").querySelector("fieldset").innerHTML;
Good answer. I think the first point would be better if it stayed var fieldset = Document.querySelector('#Blockdynamics fieldset:last-Child'); because if there are multiple Ivs with fieldset it will stop at the first
– Tiago Gomes
@Tiagogomes yes, true. I will add to the answer to clarify. Thank you.
– Sergio
Perfect! Thank you @Sergio! D
– Cleber Teixeira