1
So guys, I’m making an html page in which I’m using Typescript, and I wasn’t able to get the value of an id, until I saw in a query in the stack that should be used this way
(<HTMLInputElement>document.getElementById('ID')).value
to get value. I know that Javascript is simpler... it doesn’t need the <HTMLInputElement>
.
Can you explain to me why I need to use this and how it would be an easier way for me, that I’m making a code with many variables, to be able to use the variables without having to type in the form of the first example.
OBS: It wouldn’t be practical for me to put it this way:
var exemplo = (<HTMLInputElement>document.getElementById('EXEMPLO')).value;
because there are places I need to use the same ID to do something other than take value... like:
(<HTMLInputElement>document.getElementById('EXEMPLO')).checked = true;
I’m not using it in several places in html.... but I have to call it in different places in Typescript... so I keep repeating the code
(<HTMLInputElement>document.getElementById('ID')).value
, turns out the code gets confused– user149429
Is it to get the most current value? if it’s not just using a variable, is it open source? could post an example, if the project is large it would be better to use some framework as angular or a lib like jquery / React .
– Danielr