I have the following function that hide s a certain div when I click anywhere on a page:
$("html").click(function() {
$(".myDiv1").addClass("hidden");
});
I would like to add an exception to this function. If a click is within another div, ignore this hiding… The only way for me to select the second function is to pick a distinct element withing it:
$(".nyOtherDiv").parent()
How do I combine these? Or shall I just add it as a separate function below to overwrite the first one?
You can use event.target to see what element was clicked on. If it was that div that you want to exclude then don’t add the class else add the class.
Here’s a fiddle.