diff --git a/_posts/2019-10-14-forcing-javascript-dom-types.md b/_posts/2019-10-14-forcing-javascript-dom-types.md index fd9d2b9..165667f 100644 --- a/_posts/2019-10-14-forcing-javascript-dom-types.md +++ b/_posts/2019-10-14-forcing-javascript-dom-types.md @@ -31,10 +31,12 @@ before you assign it... 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. +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? Well, this way, the variable `x` will have the type `HTMLTableElement` all the way in your code.