jquery: val() method not working -


i have dropdown element populated through jquery ajax

    <select name="category" class="form-control"></select> 

this jquery code populating dropdown

    $.post(     "get_categories.php",     {         id: 1     }, function(data) {         $($('select[name=category]')).html(data);      } ); 

to see whether dropdown populated use console.log

     }, function(data) {         $($('select[name=category]')).html(data);         console.log(data)     } 

this i've got in browser console window

    <option value='1'>stuffed toy</option><option value='1'>plushie</option><option value='1'>memorabilia</option> 

the dropdown indeed succesfully populated test whether value change when select option included snippet:

    $('select[name=category]').change(function(){     console.log($(this).val()); }); 

after changing options ive got

    <option value='1'>stuffed toy</option><option value='1'>plushie</option><option value='1'>memorabilia</option>     1 

value of dropdown wont change @ all. i've been doing wrong?

to value dropdown can use native javascript this.value.

$('select[name=category]').change(function(){    var selectedvalue = this.value; }); 

first try see whether event getting invoked or not putting console.log inside change event.


Comments