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
Post a Comment