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
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
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.
window.onload = function() {
var div = document.getElementById('xxx');
alert(div.id)
};