Với select option trong HTML thì mình hay lấy value bằng jQuery
Giờ mình muốn lấy id hoặc class của select option bằng jQuery
<select id="my_select">
<option value="o1" id="id1">Option1</option>
<option value="o2" id="id2">Option2</option>
</select>
// lấy id
$("#my_select").change(function() {
var id = $(this).children(":selected").attr("id");
});
//lấy class
$("#my_select").change(function() {
var id = $(this).children(":selected").attr("class");
});
reference links:
https://stackoverflow.com/questions/2888446/get-the-selected-option-id-with-jquery
https://www.tutorialrepublic.com/faq/how-to-get-the-value-of-selected-option-in-a-select-box-using-jquery.php