codice:
var el = document.getElementById("pippo");
if(el) {
  //Se el esiste allora fai le operazioni
}