update js dom api post

This commit is contained in:
Ayo 2019-10-14 06:39:03 +08:00
parent 54d9818bc0
commit e828a70cbe

View file

@ -31,10 +31,12 @@ before you assign it...
x = document.getElementById('table-id') // -> always returns HTMLELement x = document.getElementById('table-id') // -> always returns HTMLELement
``` ```
If you go straight to doing `var x = document.getElementById('table-id')` the variable will have the generic type `HTMLElement`. If you go straight to doing `var x = document.getElementById('table-id')`, the variable will have the generic type `HTMLElement`... and you don't want that.
Important hint: the string parameter for `document.createElement()` (which is `'table'` in our example above) will determine the type/interface that the variable `x` will use. Important hint: the string parameter for `document.createElement()` (which is `'table'` in our example above) will determine the type/interface that the variable `x` will use.
The `'table'` parameter is the reason why we get an `HTMLTableElement` from `document.createElement()`.
## Uh, okay. But, uhm, why... woud I want to do that? ## Uh, okay. But, uhm, why... woud I want to do that?
Well, this way, the variable `x` will have the type `HTMLTableElement` all the way in your code. Well, this way, the variable `x` will have the type `HTMLTableElement` all the way in your code.