0

Consider a single div Ex ''... if i click outside the div a alert should come..... but if we click inside the div area. the alert should not come

Vijay
  • 3
  • 1
  • Duplicate of [here](http://stackoverflow.com/questions/152975/how-to-detect-a-click-outside-an-element) – Kalzem Jul 30 '12 at 05:32

2 Answers2

0

There is a jQuery plugin for this:

http://benalman.com/projects/jquery-outside-events-plugin/

Inkbug
  • 1,682
  • 1
  • 10
  • 26
0

There are two solutions.

First, you can make a flag which becomes false on entering the div and again becomes true on leaving it. Then put an onclick event on the page and check for flags value, if it is true then alert.

second, you can use two different onclick events on the div's parent and the div simultaneously, just put 'event.stopPropogation' on the onclick event of the div.

I hope these ideas might help you to get a right approach.

Tejasva Dhyani
  • 1,342
  • 1
  • 10
  • 19