Jquery Get Html Id From Selected Dropdown
As i have multiple drop-downs in my form, I would like to retrieve the HTML id from one of the selected drop-downs. I have the following code for my drop-downs on change: $('select
Solution 1:
Just use $(this).attr("id")
to get the id.
You can also use this.id
(as already mentioned in the comments). I just found a performance test for $(this).attr("id")
vs. this.id
with the result of this.id
being faster, which is expected as it's pure javascript instead of a javascript library like jQuery.
Solution 2:
You just take id
property:
$("select[name$='product_type']").change(function() {
console.log(this.id);
});
Solution 3:
$("select[name$='product_type'] option:selected").attr("id");
inside the change callback.
Post a Comment for "Jquery Get Html Id From Selected Dropdown"