I want to alter the default header on a div with a js function but after the final result of my code is the text [object HTMLDivElement]. Here is my code:
function Modelo1(){
var div=document.createElement('div');
var logo = document.createElement('img');
logo.height=80;
logo.width=250;
logo.src="persona-5-listing-thumb-01-ps4-us-30jun16.png";
var datos= document.createElement('div');
var ruc = document.createElement('span');
var dir = document.createElement('span');
var tel = document.createElement('span');
ruc.innerHTML = "RUC: ";
dir.innerHTML = "dirección aca";
tel.innerHTML = "Telefono: ";
datos.appendChild(ruc);
datos.appendChild(dir);
datos.appendChild(tel);
var doc=document.createElement('div');
doc.border="2px solid "+colorBorde;
var rD = document.createElement('span');
rD.innerHTML="ruc";
var tD = document.createElement('p');
tD.innerHTML = "HEADER";
doc.appendChild(rD);
doc.appendChild(tD);
div.appendChild(logo);
div.appendChild(datos);
div.appendChild(doc);
document.getElementById('cabecera').innerHTML = div;
}
div.innerHTML = logo + datos + div;
Is the problem
1) you can not sum html elements 2) instead + div
is + doc
function Modelo1(){ var div=document.createElement('div'); var logo = document.createElement('img'); logo.height=80; logo.width=250; logo.src="persona-5-listing-thumb-01-ps4-us-30jun16.png"; var datos= document.createElement('div'); var ruc = document.createElement('span'); var dir = document.createElement('span'); var tel = document.createElement('span'); ruc.innerHTML = "RUC: "; dir.innerHTML = "dirección aca"; tel.innerHTML = "Telefono: "; datos.appendChild(ruc); datos.appendChild(dir); datos.appendChild(tel); var doc=document.createElement('div'); doc.border="2px solid black"; var rD = document.createElement('span'); rD.innerHTML="ruc"; var tD = document.createElement('p'); tD.innerHTML = "HEADER"; doc.appendChild(rD); doc.appendChild(tD); div.appendChild(logo) div.appendChild(datos) div.appendChild(doc) document.getElementById('cabecera').appendChild(div); } Modelo1()
<header id="cabecera"></header>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.