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

106
Visualizações
updating html text on click

I would appreciate some guidance on which direction to take regarding a front-end design.

Context:

I am trying to create a page where I have 10 buttons on a top panel. Underneath this top panel will be a main panel containing N boxes of text.

Depending on what button in the top panel is clicked or active (default-button1), I want the boxes in the main panel to display the relevant boxes of text.

Example:

A restaurant menu where you have categories such as Food, Drinks, Desserts at the top. And a section which updates and shows the various options dependent on which category has been selected.

A minimal example:

3 buttons or links as Category1, Category2, Category3

Category1 should have 5 paragraphs. Category2 should have 3 paragaraphs. Category3 should have 8 paragraphs.

I am looking for an efficient way to implement this. Any pointers?

I understand the DOM allows one to dynamically render HTML using the call below, but I am confused as to how to 'grow' elements with this static approach. I am determined to learn more JavaScript.

document.getElementsByClassName(“”).innerHTML = "New text"
<!DOCTYPE html>
<html>
 <head>
   <style>
   </style>
 </head>  
 <body>
   <div class = "main_content">
    <nav>
      <ul id = "categories">
        <li>Cat 1</a></li>
        <li>Cat 2</li>
        <li>Cat 3</li>
      </ul>
    </nav>

    <article class = "items_list">
      <section class ="items">
          <!--# of <p> elements and inner HTML text for each element depends on which <li> element is currently active -->
        <p>Item A</p>
      </section>
      <section class = "items">
        <p>Item B</p>
      </section>
      <section class = "items">
        <p>Item C</p>
      </section>
    </article>
  </div>
 
 </body>
</html>
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

For every Category/Button you need to add Event Handler which will trigger a function on the event of onClick. Then according to your requirements, you can add and remove classes on paragraphs which will let you show and hide them.

Those classes can simply have display:none or display:block on it.

about 4 years ago · Santiago Gelvez 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