Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
183
rated 0 times [  188] [ 5]  / answers: 1 / hits: 34013  / 15 Years ago, mon, january 4, 2010, 12:00:00

On my web page I have a list of files.


Each file is in it's own container div (div class="file"). Inside the container is a link to the file and a description.


I wanted to allow a user to click anywhere on the container to download the file. I did this by adding a click event to the container and retrieving the href of the child link.


As the file opens in a new window, if the user actually clicks the link, the file opens twice.


So I need to prevent the parent container click event from firing when the hyperlink is clicked. Would the best way of doing this be to add a click function to the hyperlink to0 and set event.stopPropagation? Presumably this would then stop the event from bubbling up to the container.


More From » dom-events

 Answers
31

Yes, use stopPropagation. See: Prevent execution of parent event handler


[#97936] Tuesday, December 29, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
estefanib

Total Points: 508
Total Questions: 104
Total Answers: 83

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;