Get element by id and error handling