jquery - Javascript hide element (when clicked outside) with certain conditions -
so there questions here hiding div when clicking outside of it. have 1 thing, there div(accounts-edit-table-name-edit) showing hidden div(account-edit-group) on click first. , - if click somewhere else out of div(account-edit-group) - must hide. here code trying 2 different conditions (or):
$(document).click(function(event) { if($(event.target).parents().index($('.account-edit-group')) == -1 || $(event.target).parents().index($('.accounts-edit-table-name-edit')) == -1) { if($('.account-edit-group').is(":visible")) { $('.account-edit-group').removeclass('acc-edit-f'); alert("hiding") } } });
html:
<div class="accounts-edit-table-name-edit">"button"</div> <div class="account-edit-group">block</div>
(class "acc-edit-f" contains "display: block")
well, if click on div class "accounts-edit-table-name-edit" - system show me alert("hiding") though must through conditions , ignore that. there ways fix this?
see jsfiddle if want :
$(event.target).parents().index($('.account-edit-group')) //always return -1 $(event.target).parents().index($('.accounts-edit-table-name-edit')) //
Comments
Post a Comment