How to get selected value of dropdown in jQuery by name

In this article, you will learn how to get selected value of dropdown in jQuery by name attribute.

Demo : get selected value of dropdown using name.
<select name="my-element">
  <option>Drop down 1</option>
  <option>Drop down 2</option>
  <option>Drop down 3</option>
  <option>Drop down 4</option>
</select>
<script>
$("select[name='my-element']").change(function(){
  let myValue = $(this).val();
  alert(myValue);
})
</script>
Try it Yourself »