0

I am working on Grafana plugin. I need to access HTML element in module.ts file with id. I have use getElementById(). But it returns null.

My HTML code:

<div name="glg_area" id="glg_area" style="width: 86%; height: 95%; background-color: white; 
            padding: 0px;">

</div>

My .ts code :

let drawing_area = document.getElementById("glg_area");
console.log("drawing_area "+drawing_area)
  • 3
    Does this answer your question? [Why does jQuery or a DOM method such as getElementById not find the element?](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – Heretic Monkey Jan 16 '20 at 12:08
  • What version of Grafana is this for? Some version use AngularJS, later versions use React. That makes the possible solution different depending on the version. – Phil Jan 16 '20 at 12:58
  • i am using latest version of grafana 6.3.x – Yogesh Patil Jan 17 '20 at 04:06

1 Answers1

0

I have did this by importing jquery in .ts file:

import $ from "../node_modules/jquery";

console.log('drawing_area ' + $(document.getElementById('glg_area')));

will return an empty object: [object Object] which is empty