I got this issue working with TypeScript (for Angular2) when I try to get the id of an element. See this example:
<div id="search">
<div id="field1"></div>
<div id="field2"></div>
</div>
If I try to get the id of one of the nested div, I can do this normally:
var element = document.getElementById("search");
var subelement = element.childNodes;
subelement[1].id;
Then I will have "field2".
However when I try to do this with TypeScript I got the message Property 'id' does not exist on type 'Node'. And as result my code doesn't work. I really need a solution for this since I need to know the nested elements inside another, unless there are a better way.
Nodes can be more than just elements and don't necessarily have an id
property. You should use .children
which is a collection of elements only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With