Using a class name in jQuery's .closest()

后端 未结 4 505
长情又很酷
长情又很酷 2020-12-25 12:16

I\'m attempting to do some calculations for a \"running total\", this is my code:

$(\'.quantity_input\').live(\'change\',function(){         
                       


        
4条回答
  •  不知归路
    2020-12-25 13:00

    Closest will find the closest ancestor (parent, grandparent), but you will then need to do a find in order to find the correct element to update. For example, if you have an element in a table row and you need another element in that same row:

    $('.myElement').closest('tr').find('.someOtherElement');
    

    Edit:

    In your case, you will want

    $(this).closest('tr').find('.cost_of_items').text(totalTotal.toFixed(2));
    

提交回复
热议问题