Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!