There is a markup:

<div class="product-item"> <a href="#" class="product-item-img-wrap"> <img src="фото" alt="item"/> </a> <div class="item-eq-height item-info"> <div class="product-name"> <h5 class="product-item-header" style="font-size: 18px; font-weight: bold;"> Наименование </h5> </div> <div class="product-item-size" style="font-size: 14px;"> Размер и артикуль:<br /><br /> <select style="width: 224px;" name="size"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </div> <div class="product-item-price"> Цена </div> <div class="btn-wrap prod-buy-button"> <span class="btn-solid btn-add-cart" onclick="addCart(this);" style="cursor: pointer;">Купить</span> <input type="hidden" value="<?=$produсt->id?>" name="id"/> </div> </div> </div> 

In this block there is a <select name="size"> . How to access it by clicking the "Buy" button?

I do this, but it does not work:

 function addCart(btn) { $this = $(btn); var id = $this.siblings('input[name=id]').val(); var size = $this.closest('.product_list').find('select[name="size"]').val(); alert(size); } 

Closed due to the fact that it is off topic by participants aleksandr barakin , lexxl , Regent , cheops , user194374 July 30 '16 at 12:03 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - aleksandr barakin, lexxl, Regent, cheops, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    I don't see the element with the product_list class - Grundy
  • You do not have in the markup of the product_list class to which you refer to the handler. - cheops

1 answer 1

Maybe I looked inattentively, but I cannot find in your markup the product_list that is used in closest('.product_list') .
Maybe there should be a product-item ?

  • pancake ((((wrong, thanks earned - duddeniska