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

202
Views
Function to scroll and open an accordian

I am struggling to get my Javascript code to work.

I want it so that when someone clicks on the product review summary of my website that it will scroll to the reviews section and open the relevant tab.

I have managed to get the scroll part working but have been unable to get the accordian to open.

Here is a link to the site: https://mgdev.monstershop.co.uk/t-mech-5-in-1-52cc-petrol-garden-cutter-multi-tool

Here is the code i have so far.

<script>
    function viewReviews(){
        document.getElementById('customer-reviews').scrollIntoView({
        behavior: 'smooth'});
        document.getElementsByClassName('productAccordian').style.display='block';
    }
</script>

<div class="reviews-actions">
    <a class="action view" style="cursor: pointer;" onclick="viewReviews()">

This is the code that generates the accordian

      <div>
        <input id="ac-<?php echo $counter; ?>" name="accordion-1" type="radio" <?php if($counter == 1){echo 'checked';} ?>>
        <label for="ac-<?php echo $counter; ?>" class="accordion <?php if($counter == 1){echo 'active';} ?>"><strong><?= /* @noEscape */ $label ?></strong><span class="fa fa-angle-down pull-right" style="color: #6E716E;padding: 10px;"></span></label>
        <article class="productAccordian">
          <?= /* @noEscape */ $html ?>
        </article>
      </div>

I notice that when i try to open the accordian by clicking on it normally that seems to work. Just not with my new function.

Any help on this would be appriciated.

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

0

getElementsByClassName returns array of elements. Hence, the assignment is not working. You can try getElementById to make it work or document.getElementsByClassName('productAccordian')[0].style.display='block'

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!