Detect if Click is Inside an Element with JavaScript

Originally published at: Detect if Click is Inside an Element with JavaScript - Server Side Up

So this is a little script that I’ve included in some UI elements to check if a click takes place within the scope of the element. Why would you need this? Say you have a little drop down, autocomplete, etc. that should close when a click occurs outside of the element. You need to see…