Javascriptでidが存在するか確認する方法です。

idの確認コード

if( document.getElementById(“IdNmae”) ){
//idがある場合
}else{
//idがない場合
}