0

Here is html:

<div class="nama" id="xxx"></div>

And javascript :

var div = document.getElementById('xxx');
alert(div.id)

Why i am getting mistake?Looks like fine for me

Nikita Shchypylov
  • 347
  • 1
  • 3
  • 13

2 Answers2

1

The element was not found.

Most probably because this code was ran before that part of the DOM was ready.

Try placing your code below where the HTML is defined.

alex
  • 479,566
  • 201
  • 878
  • 984
1
window.onload = function() {
    var div = document.getElementById('xxx');
    alert(div.id)
};
Oxi
  • 2,918
  • 17
  • 28