check for existence of dom element before using it