Suppose I have a div named container as shown
<div id='container'>50</div>
Now if I use
var a = document.getElementById('container').value;
var b = document.getElementById('container1').value;
Here a, is fine but b gives an error
SO, is there any way to check whether a div is present or not, if, its there, I will obtain its value
document.getElementByIdwill returnundefinedif no element is found on the page. So, you can explicitly check forundefinedbefore trying to access the value.