I'm trying to get the name input element by id using "name" and print it on the console:
var name = document.getElementById("name");
console.log(name);
var surname = document.getElementById("surname");
console.log(surname);
var select = document.querySelector("select");
console.log(select);
select.addEventListener("mouseleave", function(){
console.log(select);
var optionSelected = select.value;
console.log(optionSelected);
if (optionSelected === "beginner"){
alert("it works!!!");
}
})
but I get this on the first console.log:
[object HTMLInputElement]
As soon as I rename var name into var obj and do console.log(obj), i get the correct element printed on the console:
<input type="text" id="name" value="hi">
This behaviour is quite strange because the surname input doesn't give any problem.
I'm using Visual Studio Code and Google Chrome.