1

I have an element in HTML with div tag and an id, I need to access the contents in a JavaScript file which is included in the HTML.

This is in HTML

    var obj = document.getElementById("x").innerHTML;
    alert(obj);
<div id="x">0.576308782559139</div>

It does not print anything.

I did check the console, and it says "cannot read property innerhtml of null" However, in console if I do document.getElementById("x").innerHTML it prints the contents of div.

Prabhanjan
  • 155
  • 1
  • 8

0 Answers0