I am having a bit of an issue with showing and hiding a menu using jQuery. What I am trying to do is:
If a button is pressed, then show a menu div. If the somewhere other than the div is clicked, hide the menu div.
Here's where my issue comes in. The above works perfectly, but when you click on an element which is inside of the div, the menu is hidden, which is not my intended outcome. My code is as follows:
$(document).ready(function() {
$(document).click(function(e) {
if (e.target.id != "projectEdit") {
if (e.target.id != "projectEditMenu") {
$("#projectEditMenu").hide();
}
} else {
$("#projectEditMenu").show();
}
});
});
How can I make it so that if the children of the menu div were excluded from this argument, it keeps the menu open if the children are clicked on?
HTML code:
<div id="projectEditMenu">
<div id="projectEditMenuMarker"></div>
<div id="projectEditMenuAddTile">
<span id="projectEditMenuAddTileTitle">Add Tile</span>
<form id="newTileForm" action="openProject.php" method="put" hidden></form>
<input form="newTileForm" type="text" name="newTileName" id="newTileNameInput" placeholder="Tile Name">
</div>
</div>