jQuery Detect Click Outside of Element
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html> <head> <title>jQuery Demo example</title> <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"> </script> <script type="text/javascript"> $(document).click(function (e) { if(!$(e.target).is('#myDiv')){ alert("Clicked Out Side"); } }); </script> </head> <body> <div id="myDiv" style="width:200px;height:200px;background:yellow;"> <h2>Click OutSide</h2> </div> </body> </html>
<!DOCTYPE html> <html> <head> <title>jQuery Demo example</title> <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"> </script> <script type="text/javascript"> $(document).click(function (e) { if(!$(e.target).is('#myDiv')){ alert("Clicked Out Side"); } }); </script> </head> <body> <div id="myDiv" style="width:200px;height:200px;background:yellow;"> <h2>Click OutSide</h2> </div> </body> </html>
Copyrights@tutorialsplane.com