Cited a test example from the site for convenience. It seems to be all the rules: pressing the basket button and the appearance of the counter of goods. After reloading the page on the site, there will be no button or counter (because in the css, the counter of goods "num" display: none). Please help, how to implement a condition check: if the counter element is visible, then hide the button, otherwise, show the add to cart button
$('.add2cart').click(function(e) { e.preventDefault(); $(this).hide(); $(this).prev('.num').show(); }); .num { display: none; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input class="num" type="number" placeholder="ΠΊΠΎΠ»-Π²ΠΎ"> <a class="add2cart" href=""> <img src="https://d30y9cdsu7xlg0.cloudfront.net/png/38919-200.png" alt=""> </a> I tried to make this condition:
if ( $( ".add2cart" ).length ) { $( ".num" ).show(); } else { $( ".num" ).hide(); }
ΠΠΎΡΠ»Π΅ ΠΏΠ΅ΡΠ΅Π·Π°Π³ΡΡΠ·ΠΊΠΈ ΡΡΡΠ°Π½ΠΈΡΡ Π½Π° ΡΠ°ΠΉΡΠ΅ ΡΠΆΠ΅ Π½Π΅ Π±ΡΠ΄Π΅Ρ Π½ΠΈ ΠΊΠ½ΠΎΠΏΠΊΠΈ- well, yes, the button itself disappears. - Rustam Gimranov