• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Suppress click on page once already clicked on image

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tons of thanks both of you! This was exactly what I was looking for!
 
reply
    Bookmark Topic Watch Topic
  • New Topic