web 2.0

Event Bubbling in Javascript

Today, while creating some javascript popup I had a condition in which I place onclick function on body tag. I had an other button which also implement onclick. So the code looks like as follows

   1: <body onclick="disappearPopup()">
   2: <a href="#" onclick="ShowPopup()">Show me</a>
   3: </body>

So, what happen is whenever link is click the body clicked even called automatically. Practically speaking, we need to cancel the body onclick even each time we click the link click.

And for that I write the following code on click of the link

   1: if (window.event) {
   2:     window.event.cancelBubble = true;
   3: }
   4: else {
   5:     e.stopPropagation();
   6: }

And it works ....

Comments

shakeeb khan , on 12/19/2008 12:00:39 PM Said:

shakeeb khan

agha this thing can be achievable easily through jquery if any body want it so i will add tutorial Laughing

Junaid Ahmed Saudi Arabia, on 6/5/2009 8:27:37 AM Said:

Junaid Ahmed

Thanks Agha, for posting this issue...keep it up!  

sheartech United States, on 8/24/2009 6:27:27 AM Said:

sheartech

this thing is easy for many, but this helped some of the readers of this blog.

Montures lunettes United States, on 11/14/2009 12:44:36 AM Said:

Montures lunettes

Dude.. I am not much into reading, but somehow I got to read lots of articles on your blog. Its amazing how interesting it is for me to visit you very often.

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading