I'm a JS self-learner. Currently jQuery. So please don't downgrade me. I made an age checker app. But the combination input type number + submit button only works after a page refresh. Is it possible to change the age after submitting it once and see the style changes without a page reload?
What I mean is that after loading the page, my app works only once. Then console log doesn't show any change in the input field and clicking submit.
<div class="container">
<form>
<label for="age">Check your age</label>
<input type="number" min="5" max="100" id="ageInput" onfocus="this.value=''">
<input id="inpBtn" type="button" value="Submit">
</form>
<div id="underage">
<p>You need to get older. You're underage.</p>
</div>
<div id="ofAge">
<p>You are good to go.</p>
</div>
<div id="tooOld">
<p>You are too old for this club</p>
</div>
let ageInput = document.querySelector("#ageInput").value;
$(document).ready(function(){
$("#inpBtn").click(function(){
console.log(ageInput);
if(ageInput < 18) {
$("#underage").css("color", "red");
console.log("under 18");
} else if (ageInput >= 18 && ageInput < 80) {
$("#ofAge").css("color", "green")
console.log("good to go");
} else {
$("#tooOld").css("color", "gray")
console.log("too old");
}
});
});