Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Javascript Grid/List View issue with initial page load

For my shop page I have a grid view with two columns and options to switch to list view. It's all working well except when the page initially loads; the products are displaying in four columns.

var elements = document.getElementsByClassName("product");
var image = document.getElementsByClassName("attachment-woocommerce_thumbnail size-woocommerce_thumbnail jetpack-lazy-image jetpack-lazy-image--handled lazyloaded");
var i;

function listView(){
  for(i = 0; i < elements.length; i++){
      elements[i].style.width = "100%";
      elements[i].style.height = "15.1vw";
      image[i].style.width = "29%";
      
  }
}

function gridView(){
  for(i = 0; i < elements.length; i++){
      elements[i].style.width = "35%";
      elements[i].style.height = "35vw";
      image[i].style.width = "100%";

      
  }
}

I removed the default style. Is there a way to create a function to run a style only when the page initially loads?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda