This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Suppress click on page once already clicked on image

 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have an image on a page, on clicking which an event handler should be called.
The image lies inside a TD (table cell) which has its own click handler.



(spelling of onclikk changed for this message only)
On clicking the 'menu.png' , showMenu() function should be called and clicking anywhere else in the cell should call hideMenu() function.

But when I click on image the hideMenu() is called, not showMenu.

Can you please tell me what should I do? Is there any better approach (if this is wrong)? Any pointers will help.

Thanks
 
Satish Chilukuri
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have nested elements and they have the same event listeners, depending on how you add listeners, events will be fired in different order. See this page

My guess is showMenu() is getting called first and then immediately hideMenu() is getting called.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into Event Bubbling and how to cancel it.

Eric
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tons of thanks both of you! This was exactly what I was looking for!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic