Find $ (this) selected value in jQuery

Can't solve it ...

I have an event handler .changefor several select blocks. I need to find the selected value each time. I can not figure out how to use .valwith $(this).

So here is my code:

$(document).ready(function(){
  $("select.className").change(function() {

    //console.log($(this).val);
    //console.log($("option:selected",this).val);
  })
})

Both of the above return a function, not the selected value that I am looking for.

Any help would be great. Thank.

+5
source share
2 answers

Like everything else in jQuery, it valis a function.
You need to call a function, for example .$(this).val()

+9
source

.val is a method, not a property. You will need to call it using parens:

//console.log($(this).val());
//console.log($("option:selected",this).val());
+8
source

All Articles