Fix html error: only close div if it was opened