if(document.getElementById('tuoId')){
...istruzioni...
}