Opening Accordion On Click

mustaphadem
Tourist
7 0 0

Hello, 

 

I am trying to scroll down and open my reviews accordion when clicked on the reviews star badge, both are on the same page.

 

this what i am trying;

<a href="#1500666216949" class="starbadge" onclick="myFunction()" > <span class="shopify-product-reviews-badge" data-id="{{ product.id }}"></span></a>

<script>
function myFunction() {
  document.getElementById("1500666216949").scrollIntoView(true);
  document.getElementById("1500666216949").click();
}
</script>

 

It get it to scroll, but click event does not occur. Can someone tell me what i am doing wrong, pretty please?

 

Thank you, 

0 Likes
mustaphadem
Tourist
7 0 0

Okay, so I have moved it a bit,..

Using the following one it hides the review section completely rather than expanding the accordion content and reveals it back on the second click lol 

 

 

 

<a href="#1500666216949" class="starbadge" onclick="toggle_visibility('1500666216949');" > <span class="shopify-product-reviews-badge" data-id="{{ product.id }}"></span></a>

<script>
function toggle_visibility(id) {
  
  var e = document.getElementById(id);
  		e.scrollIntoView();   
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
</script>	

 

 

 

Any ideas?

0 Likes
mustaphadem
Tourist
7 0 0

Does anyone have an idea by any chance on this one?

Thank you very much,

0 Likes