idが存在するかを調べる

if( document.getElementById("hoge") )
{
	alert("ある");
}
else
{
	alert("ない");
}