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

150
Visualizações
How do I save table style visibility style after reload / refreshing page?

I have a table containing a table, aka nested tables. (Person -> Pets data for example). First table displays all people, second table shows pets for each person.

I have a button which shows the nested table, this shows/hides the table data containing the pets.

JAVASCRIPT:

function toggletable(id) {
  var tableid = document.getElementById(id);
  tableid.style.display = (tableid.style.display == "table") ? "none" : "table";
}

  

Now, if I refresh the page all tables are "none" again. However, I want so that if I open a table, aka click on the button that calls the function to open it, if I refresh the page it should be open again.

Here is the button

button id="toggleTableDisplay" class="button-sma" onclick="toggleTable((php echo ($data->get('id')); ?>) php echo "Show pets"?></button>

Here is the table

table name="php echo ($data->get('id')); ?>" style="display: none"  id="php echo ($data->get('id'));"

I'm not 100% sure how the formatting here works but I had to change the code so if you copy/paste it won't work as I've had to remove some ?> etc.

I put it in a pastebin here:

https://pastebin.com/YH1xS4XB

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

localStorage keeps key->value pairs. So you might store tables id's as keys (since you'r using id's already) and an integer 1 for visibility flag as a value. When you reveal a table you just run something like:

localStorage.setItem(table_id, '1');

When you hide it, just drop the entry:

localStorage.removeItem(table_id);

And on page load you walk through your tables and show them if localStorage entry exists (jQuery here):

$('table').each(function(){
    if( localStorage.getItem( $(this).attr('id') ) )
         $(this).show();
})
about 4 years ago · Juan Pablo Isaza Relatório
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