close element unless closed element already exists jquery code example
Example: check element exist in jquery
if ($('.element').length) {
// there is at least one element matching the selector
}
if ($('.element').length) {
// there is at least one element matching the selector
}