S.M_Emamian
S.M_Emamian

Reputation: 17383

How to get an attr value by class name and filter function

I have a lot of inputs like this :

<input cat-id="13" cart-id="11" coupon-property_id="0" pay-user="7800" off="61" price="20000" coupon-id="16669" max-buy="100" name="cart-quantity" class="cart-quantity info-coupon" value="1" disabled="" type="text">

that them have different values .

now, I have two question :

  1. how can i get cat-id value by using jquery ?

    function removeInCart(id){
    
    var cart_id = $('.cart-quantity .info-coupon').filter('input[cart-id='+id+']').attr();
      }
    

it returns a jquery error.

  1. Did I properly define extra-values like cart-id,cat-id coupon-propery_id ... in input element ? or I should use data-cart-id,data-cat-id ... ?

Upvotes: 1

Views: 47

Answers (1)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this :remove space between .cart-quantity and .info-coupon and put attribute name in attr() function

var cart_id = $('.cart-quantity.info-coupon').filter('input[cart-id='+id+']').attr('cat-id');

Upvotes: 1

Related Questions