See months of the Javascript calendar

2

I'm trying to make a calendar like this web: link what instead of the months they appear to me vertically, I would like four months to appear for each line, in plan January-February-March-April and then 4 more and so ...

The step I'm going through is the following:

var mes_text = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];

function estructurar() {
	for (m = 0; m <= 11; m++) {
  //Mes
  let mes = document.createElement("DIV");
  mes.className = "mes";
  document.body.appendChild(mes);
  //Tabla
  let tabla_mes = document.createElement("TABLE");
  tabla_mes.className = "tabla_mes";
  mes.appendChild(tabla_mes);
  //Título
  let titulo = document.createElement("CAPTION");
  titulo.className = "titulo";
  titulo.innerText = mes_text[m];
  tabla_mes.appendChild(titulo);
}
}

I guess it will have to do with the AppendChild but I'm not sure, I'm practicing to learn. Thank you very much for your help.

    
asked by Joume Parra 25.06.2018 в 18:19
source

1 answer

1

I do not know why you are creating one table per month. I would make a single table that contains all the months. Something like this:

var mes_text = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];

function estructurar() {
  let mes = document.createElement("DIV");
  mes.className = "mes";
  document.body.appendChild(mes);
  let tabla_mes = document.createElement("TABLE");
  tabla_mes.className = "tabla_mes";
  mes.appendChild(tabla_mes);
  let tr = "";
  for (m = 0; m <= 11; m++) {    
    if (m % 4 == 0) {
      tr = tabla_mes.insertRow(m / 4);
    }
    var cell = document.createElement("td");    
    var cellText = document.createTextNode(mes_text[m]);  
    
    cell.appendChild(cellText);
    tr.appendChild(cell);
    
  }
}
estructurar();
    
answered by 25.06.2018 / 18:31
source