I am using same css for a select dropdown and a input textbox. I set the values in jquery like this:
$('.a').val('2');
When checking the value of the select and input elements, they are correctly assigned but when I display their values via console.log, I get undefined for both. Why is that?
console.log($('.a').find('select').val());
console.log($('.a').find('input').val());
Result:
undefined
undefined
Here's my fiddle: http://jsfiddle.net/04oLs3he/12/
find? it makes a big difference. you needselect.aandinput.afind()as it won't be the right way to do that, however you can use.filter()but it will be an overkill operation here, the easiest way is to useselect.aandinput.aas suggested by @TemaniAfif.