jquery - Disable Button if data-quantity is less than 1 -


i want disable following button if "data-quantity" attribute less 1. can't figure out how form if statement this.

<button type="submit" data-product_id="1" data-product_sku="test" data-quantity="0" class="add_to_cart_button button product_type_simple">add cart</button> 

i've tried this:

var cart_button = $('.add_to_cart_button'); if(cart_button.attr("data-quantity") < 1) {     cart_button.prop("disabled", true); } 

jquery has built-in ability read (and set if need be) data tags. use .data() syntax. note, drop "data-" prefix when using property. also, sure wrapping in document.ready function.

$(function(){     var cart_button = $('.add_to_cart_button');     if(cart_button.data("quantity") < 1) {         cart_button.prop("disabled", true);     } }); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -