My html syntax is as below
<select id="category" name="category">
<option value="0">Please Select</option>
<option value="50" data-value="akne">ACNE</option>
<option value="11" data-value="rednessbumps">Redness / Bumps</option>
<option value="15" data-value="sunspotsfreckles">Sunspots / Freckles</option>
<option value="16" data-value="agingwrinkles">Aging / Wrinkles</option>
<option value="17" data-value="dry-sensitive">Dry Sensitive</option>
</select>
$("#category").change(function () {
var selectedItem = $(this).val();
var abc=$(this).attr("data-value");
});
Here I am not able to get the data-value
in jquery, How should I get that?
Use
var abc = $('option:selected',this).data("value");
Try
$("#category").change(function() {
var selectedItem = $(this).val();
var abc = $('option:selected',this).data("value");
alert(abc);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="category" name="category">
<option value="0">Please Select</option>
<option value="50" data-value="akne">ACNE</option>
<option value="11" data-value="rednessbumps">Redness / Bumps</option>
<option value="15" data-value="sunspotsfreckles">Sunspots / Freckles</option>
<option value="16" data-value="agingwrinkles">Aging / Wrinkles</option>
<option value="17" data-value="dry-sensitive">Dry Sensitive</option>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With