6
I discovered that there is a new way to rescue and define values to any HTML tag, using its ID as a variable:
<html>
<head>
<title>Meu Teste</title>
</head>
<body>
<input id="testeVariavel">
</body>
</html>
JAVASCRIPT
/*1- Utilizando o ID da TAG como variável*/
testeVariavel.value = "teste"
/*2- Forma tradicional*/
var testeVar = document.querySelector('#testeVariavel');
testeVar.value = "teste 2"
I wonder if it is a good practice to use the first way I exemplify in the code above Javascript, as I saw that this is much more practical than the normal method (since I can even work with functions).
Both demonstrated ways, I can define any value for my input, but saving on the code and leaving "apparently" more optimized.
I have some future impact by using this more practical way as it is very similar to a global variable as well, because in theory I can access the element whenever I want to set or redeem a value.
The ID was made to anchor objects, when you use as a tag, you are disconnecting from the anchored element, so I believe it has nothing to do with good or bad practice, but what the expected result.
– Ivan Ferrer