php - Fetching attribute on change event Jquery -


i have specified attribute tag want fetch using jquery.

<select id='duration' name='duration'>   <option value=''>select duration</option>   <option value='10' data-cost='50'>10 min</option> </select> 

here jquery code.

$(document).ready(function(){    $('#duration').change(function(){        var cst=$(this).data('cost');   // not working        var cst=$('#duration').data('cost');        alert(cst);     }); }); 

it showing value undefined in alert. i'm doing wrong ?

data attribute of option tag not select tag this represent select tag

try jsfiddle

$(document).ready(function(){    $('#duration').change(function(){        var cst=$(":selected",this).data('cost');   // not working        alert(cst);        }); }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -