ho trovato con
if (document.getelementbyid('nome elemento')) {
esegui operazioni
}