How do you check if a page click was inside a specific <div> or not?
I have a <div> with nested children, so the $("div").click() method does not work, because clicking on other elements inside will not call anything.
I need exactly this: I click on 1 element on the page and show another more complex <div> . When I go beyond this <div> , I need to hide it.
It seems simple, but I could not solve it for several hours.
I cannot use focus / blur because it describes an element.
I need the following: I click on one element - in this case - a link, and then assign it a class. Then I put the same class in the parent element of the link. This is because I need to show which <div> is the link's sibling.
In my CSS, I have something like parent.class{ mydiv{display:block;} }) .
When I click on another place on the page, I need to delete these classes. The problem is that when I click inside the <div> shown, my function thinks I clicked somewhere on the page and deleted the classes.
source share