Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda