Checking if a div exists is fairly simple
if(document.getif(document.getElementById(\'if\')){
}
But how can I check if a div with the give
var myElem = document.getElementById('myElementId');
if (myElem === null) alert('does not exist!');
Check both my JavaScript and JQuery code :
JavaScript:
if (!document.getElementById('MyElementId')){
alert('Does not exist!');
}
JQuery:
if (!$("#MyElementId").length){
alert('Does not exist!');
}
That works with :
var element = document.getElementById('myElem');
if (typeof (element) != undefined && typeof (element) != null && typeof (element) != 'undefined') {
console.log('element exists');
}
else{
console.log('element NOT exists');
}