使用document.getElementById()访问HTML元素时返回null
我正在开发Grafana插件。我需要访问module.ts文件中id为的HTML元素。我已使用getElementById()。但它返回null 我的HTML代码:使用document.getElementById()访问HTML元素时返回null,html,typescript,grafana,Html,Typescript,Grafana,我正在开发Grafana插件。我需要访问module.ts文件中id为的HTML元素。我已使用getElementById()。但它返回null 我的HTML代码: <div name="glg_area" id="glg_area" style="width: 86%; height: 95%; background-color: white; padding: 0px;"> </div> 我通过在.ts文件中导入jquery实现了这一点:
<div name="glg_area" id="glg_area" style="width: 86%; height: 95%; background-color: white;
padding: 0px;">
</div>
我通过在.ts文件中导入jquery实现了这一点:
import $ from "../node_modules/jquery";
console.log('drawing_area ' + $(document.getElementById('glg_area')));
将返回一个空对象:[object object]它是空的这是否回答了您的问题?这是什么版本的Grafana?一些版本使用AngularJS,更高版本使用React。这使得可能的解决方案因版本而异。我使用的是grafana 6.3.x的最新版本
import $ from "../node_modules/jquery";
console.log('drawing_area ' + $(document.getElementById('glg_area')));