How to avoid typescript error: Property 'innerHTML' does not exist on type 'Element'

后端 未结 6 2000
时光说笑
时光说笑 2020-12-16 09:14

I\'m trying to place some HTML inside a specific div. When I try this in typescript I get this error: Property \'innerHTML\' does not exist on type \'Element\'

6条回答
  •  别那么骄傲
    2020-12-16 09:43

    I had the same issue, solved it by declaring it as:

    myString = 'hello world';
    
    var el: HTMLElement = document.getElementById('id_of_element');
    el.innerHTML = myString;
    

提交回复
热议问题