0

hello I would like when I click on add, to make the div appear

for example if I click on ajouter au panier of article 2001 only the class panel of this article can be displayed

if I click on ajouter au panier of article 2002 that the class linked to this article can be displayed

if I click on ajouter au panier of article 2003 that the class linked to this article can be displayed

But my code does not work I have an error message Uncaught TypeError: Cannot set properties of undefined (setting 'display')"

                     <a data-nom="2001" class="btn btn-primary ajouter-panier b-items__item__add-to-cart" onclick="myFunction();">
                       ajouter au panier
                     </a><br>

                     <div class="panel" style="display:none">
                       <a data-qte2="0" class=" ajouter-panier ">
                         retirer panier
                       </a><br>
                     </div>
                     <a data-nom="2002" class="btn btn-primary ajouter-panier b-items__item__add-to-cart" onclick="myFunction();">
                       ajouter au panier
                    </a><br>

                     <div class="panel" style="display:none">
                       <a data-qte2="0" class=" ajouter-panier ">
                         retirer panier
                       </a><br>
                     </div>
                     <a data-nom="2003" class="btn btn-primary ajouter-panier b-items__item__add-to-cart" onclick="myFunction();">
                       ajouter au panier
                     </a><br>

                     <div class="panel" style="display:none">
                       <a data-qte2="0" class=" ajouter-panier ">
                         retirer panier
                       </a>
<script>
function myFunction() {
 var a = document.querySelectorAll(".panel[style*='display:none']");
 console.log ("display",a)
a[0].style.display ='block'; 
}

function myFunction2() {
 var b = document.querySelectorAll(".panel[style*='display:block']");
 console.log ("display",b)
b[0].style.display ='none'; 
}
</script>
jules
  • 1
  • 1

0 Answers0