a simple question: Based on the codes below, I would like to ask a question, is it possible for me to rewrite the elements using Javascript that were inside "person-infos" after having them removed by Javascript?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Testes</title>
</head>
<body>
<div class="person-infos">
<img class="photo">
<div class="name"></div>
<div class="age"></div>
</div>
<script src="testes.js"></script>
</body>
</html>
const infos = document.querySelector(".person-infos")
const nomeCandidato = document.querySelector(".name")
const partidoCandidato = document.querySelector(".age")
const elementsInfo = infos.children
infos.remove()
2
Answers
If you mean you want to recreate those elements using Javascript after having them removed. You can use the createElement property on the document object to achieve that. Then append the created element to the div with class ‘person-infos’. A demonstration to that is.
I hope this answers your question.
Just as @Barmar said you can use createElement and appenChild to create and then append element into the DOM. If you want to add an element before others use prepend