简体   繁体   中英

Performing action after getting value of button

Can anyone tell me whats wrong with this code? Ive already got it to alert the value of the button by using alert(y) and getting back 2437 but as soon as i put this condition statement in its not even giving me an alert.

Im sure its something simple but im not seeing it.

jQuery(document).ready(function( $ ){
   if( $('body.single-product').length || $('body.single-product').length ){
   var x = document.getElementsByClassName("single_add_to_cart_button");
   var y = x[0].value;
   if y == 2437 {
     alert("Yes");
   }else{
     alert("No");
   }
  }
});

You have an error in your javascript code right here: if y == 2437

Correct it to this:

jQuery(document).ready(function( $ ){
 if( $('body.single-product').length || $('body.single-product').length ){
   var x = document.getElementsByClassName("single_add_to_cart_button");
   var y = x[0].value;
   if (y == 2437) {
     alert("Yes");
   }else{
     alert("No");
   }
 }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM