Hello, I have a function in Javascript
using DOM
to create a page and then
I want to display this same page in the container
and for this the data displayed would have to be only the intended one and only that container does not clear
to delete the content as it shows in figura 2
.
I have this figura 1
, it shows the first page created, source view HTML element placed on page using DOM - Javascript
andwhenIselectpiso
andIwanttoseethecontentthroughbutton
viewFloorandIhavetheeventscript
/***Funçãoparavisualizardadosnopiso**/Consola.prototype.onVerClick=function(event){this.pisos.forEach(function(piso,indice){if((piso.selected)&&(pisoinstanceofPiso)){//chamaafunçãopiso.criarCompartimento();}});}
andIwanttoseethispagewithinthesamecontainer
,asshownbyfigura2
função
hasbeenimplementedinthisscript
/***Funçãoparacriarcompartimento*/Piso.prototype.criarCompartimento=function(){varh1=document.createElement("h1")
h1.style.color = "#ff0000";
h1.style.textAlign = "center";
var textoPiso = document.createTextNode("Piso " + this.id);
h1.appendChild(textoPiso);
var h2 = document.createElement("h2")
h2.style.color = "#0000ff";
h2.style.textAlign = "center";
var textoCompartimentos = document.createTextNode("Compartimentos:");
h2.appendChild(document.createElement("br"));
h2.appendChild(textoCompartimentos);
var btnCriar = document.createElement("button");
var btnCriarText = document.createTextNode("Criar");
btnCriar.appendChild(btnCriarText);
var btnApagar = document.createElement("button");
var btnApagarText = document.createTextNode("Apagar");
btnApagar.appendChild(btnApagarText);
var btnSistemaDom = document.createElement("button");
var btnSistemaDomText = document.createTextNode("Sistema Domótico");
btnSistemaDom.appendChild(btnSistemaDomText);
container.appendChild(h1); //adicionar itens ao container
container.appendChild(h2);
container.appendChild(btnCriar);
container.appendChild(btnApagar);
container.appendChild(btnSistemaDom);
}
and I was able to do just that, as shown by figura 3
AndanotherquestionaroseisthatifIwanttoreturntocontainer
mainconsola1
,itispossiblewithoutlosingdata,soIwillhavetocreateanewfunção
,orcreateevento
foronenewbuttonretroceder
oristhereanothersolution?
Thefinalgoalistoreachatleastthisstructure,asshowninfigura4
,somepageshavealreadybeenimplementedseparatelyandonlyneedtosynchronize