I have a list:

<select name="variantId" onchange="alert($(this).has('option:selected').attr('data-price'));"> <option value="209" data-price="4000">500 мл</option> <option value="208" data-price="1850">250 мл</option> <option value="207" data-price="950">100 мл</option> <option value="206" data-price="460">50 мл</option> <option value="205" data-price="220">25 мл</option> <option value="204" data-price="100">10 мл</option> </select> 

Why he does not deduce the price from the data-price attribute, and writes undefined? Maybe because I have xhtml, and data-price from html5?

Then what attribute can be used to set the third parameter for the field?

    1 answer 1

    RTFM .has ()

    Description: This is a descendant that matches the selector or DOM element.

     <select name="variantId" onchange="alert($(this).find('option:selected').attr('data-price'));">