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

178
Views
How can I show different paragraphs with one function

I want to show a paragraph if I click on the title. The issue I'm having is that I have multiple titles with each a different paragraph but only one function to handle it. Is this even possible? The function only shows the paragraph for the first title.

I have tried with:

document.querySelectorAll(".class1, .class2")
document.getElementsByClassName("class1 class2")

Both don't seem to work.

function unhide() {
    var hid = document.querySelectorAll(".lefthanded", ".measurements");
    // Emulates jQuery $(element).is(':hidden');
    if(hid[0].offsetWidth > 0 && hid[0].offsetHeight > 0) {
        hid[0].style.visibility = "visible";
    }
}
            <a onclick="unhide()"><h3>Preinstalled Left Hand Kit</h3></a>
            <div class="lefthanded">
                <p>This is the paragraph</p>
            </div>

            <a onclick="unhide()"><h3>Product Measurements Requests</h3></a>
            <div class="measurements">
                <p>This is a different paragraph</p>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

One of the quick easy and efficient ways to tackle this is use <detail> tag like this:

<details>
  <summary>Your Title</summary>
  <p>This is your paragraph</p>
</details>

More about the tag

about 4 years ago · Juan Pablo Isaza Report

0

$("#lefthanded").click(function(){
    $(".lefthanded").show();
  }); 
  $("#measurements").click(function(){
    $(".measurements").show();
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


            <a id="lefthanded"><h3>Preinstalled Left Hand Kit</h3></a>
            <div style="display: none;" class="lefthanded">
                <p>This is the paragraph</p>
            </div>

            <a id="measurements"><h3>Product Measurements Requests</h3></a>
            <div style="display: none;" class="measurements">
                <p>This is a different paragraph</p>
            </div>

The easy way to do this is (With Jquery): Just target the paragraph Hide it with .hide() method. The show it on click with the selector ($selector).click(()=>{$(paragraph#id).show()}) In this way you can easily do the work.

about 4 years ago · Juan Pablo Isaza 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!