1var element = document.getElementById("test");
2 //If it isn't "undefined" and it isn't "null", then it exists.
3if(typeof(element) != 'undefined' && element != null){
4 alert('Element exists');
5} else{
6 alert('Element does not exist');
7}
8
1var myElement = document.getElementById("myElementID");
2
3if(!myElement){
4 //#myElementID element DOES NOT exist
5}
6
7if(myElement){
8 //#myElementID element DOES exists
9}