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

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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