-1

getElementsByClassName does not work. Here is my code.

$(document).ready(function() {
  $('.parent<?php echo $product['product_id']; ?>').on("click",function(){
 
       if( document.getElementsByClassName('sub-nav').style.display == 'block' )
       document.getElementsByClassName('sub-nav').style.display = "none";

       $(haid<?php echo $product['product_id']; ?>).toggle();
       $(haid<?php echo $product['product_id']; ?>).siblings().find(".sub-nav").hide();
      });
});

I have separate buttons with unique generated ID and I want to search them by class. What I am trying to do is when button A is clicked the button B to hide. The toggle does not function because it cannot find the unique ID for the other button.

if getElementsByClassName finds that there is display:block just to replace it with display:none; and go on with the opening of the clicked button.

1 Answers1

0

i did it. Thank you guys!

 if($(".sub-nav").css("display","block")) {
  $(".sub-nav").css("display","none");
  } else {
  $(".sub-nav").css("display","block");}