Read the
"Attributes vs. Properties" section of
the documentation[
^].
The value of the
disabled
attribute is the string
"disabled"
.
The value of the
disabled
property is
true
or
false
.
Change your code to use
.prop("disabled", false)
instead of
.attr("disabled", false)
.
Also read the documentation for
the ready
event[
^]: the
$(document).ready(...)
syntax has been deprecated since jQuery v3. The recommended version is simply
$(...)
, which does the same thing.
$(function () {
$('#numberOfRooms').on('change', function () {
let val = $('#numberOfRooms').val();
console.log(val);
if (val == 0) {
$('#numberOfPeople').prop('disabled', true);
} else {
$('#numberOfPeople').prop('disabled', false);
}
})
})