I’m having a little trouble with this JQuery function.
Basically, I have a div, that when clicked, shows another Div. It’s set to a toggle, actually, so it toggles on/off when you click.
I want to have it where if you click on anywhere outside of the opened div (that appears after you click on the first div), the div that was opened is closed.
I thought I could do this by simply binding a click event to a parent container div, but it seems that the click event carries to all child elements as well, and then the div never opens when you click.
Does that make any sense?
Thanks in advance for any help!
Here is a solution I think: Click ME
Explanation: If you klick on a link or a div with the ID ’#link’ it will toggle the div with the ID ’#divLoginBox1’
The return false is for not consulting a anchor or something.
If you click on the same link again the ‘e.stopPropagation();’ will cancel your action.
If you click somewhere else the div will hide.
I hope it helps you!
Thank you so much; that works wonderfully! I greatly appreciate you taking the time to write out the code for me.
Also, showing me that IF statement helps me when I don’t want to use toggle(), so I learned something there too.
THANK YOU !
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.