I am attempting to create a function where an element is hidden whenever the user clicks outside of it.
When the CART link in the top left corner is clicked, a dropdown appears. However, I am encountering two issues.
1) The dropdown is being shown and then hidden when anything other than just clicking on CART is clicked. I believe the problem lies in targeting the correct classes in the following code snippet:
$(document).click (function (e) {
if (e.target != $('.cart-dropdown')[0] && e.target != $('.cart-nav-item')[0] && e.target != $('.cart-full')[0]) {
$('.cart-dropdown').hide();
}
});
2) Additionally, the .cart-dropdown DIV closes when clicked within it, which is not the desired behavior. This issue may also be related to an error in the code above.
If anyone could provide guidance on how to resolve these problems, I would greatly appreciate it.
Thank you.