Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • I would use this instead, because we already have the context established for the element in the setup for the event. var selectedValue = $(e.target || this).val(); Commented Jan 20, 2017 at 11:47
  • Sorry, I don't understand Commented Jan 20, 2017 at 12:03
  • Using var test = $('#sampleSelect').val(); is pointless when you know the event is already for that element. By doing what you did, you are RE-QUERYING for the object. You actually already have it. You can use this or you can set e (for the incoming event param) and use e.target to get the value. Commented Jan 20, 2017 at 12:15
  • Simply: $(document).on('change', '#sampleSelect', function(e) { var test = $(e.target).val(); // or $(this).val(); }); Commented Jan 20, 2017 at 12:16
  • Sorry, I thought you were OP. Yes, $('#sampleSelect').val() could be $(this).val() or this.value. Commented Jan 20, 2017 at 12:16