This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Preventing event propagation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Preventing event propagation" Watch "Preventing event propagation" New topic
Author

Preventing event propagation

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
I have some code similar to the following. There is an onclick handler on a div element which contains an embedded anchor element. Clicking on the anchor element always seems to invoke the the div onclick handler. The desired action is to have the browser open the default email editor and return with div element onclick event invoked when a user clicks anywhere inside the div element EXCEPT for the anchor link. Is this possible? The application uses jQuery so I have access to that functionality if jQuery contains some way to achieve the desired action.



Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60789
    
  65

In the click handler you can examine the target of the event and let it propagate if it's an anchor, or do whatever else you want to do if it's not.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Thanks Bear! That's exactly what I needed to do.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60789
    
  65

 
 
subject: Preventing event propagation
 
Similar Threads
jQuery AJAX display issue
jQuery not working on page
How do I conditionally remove link from jsp?**********
Spring jQuery form submit request.getSession(false) returns session but with a new session id
Need help selecting a value from a list with multiple ids that are the same