Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:14:35+00:00 2026-06-10T05:14:35+00:00

I have a div and within the div there is a child img element.

  • 0

I have a div and within the div there is a child img element.
Both div and img have their very own javascript click handler.

My objective is to have when I click on the img, only the img click is triggered.
But currently the div click handler is responding before the img click handler.

Here’s the example: http://jsfiddle.net/5j73w/

I’m not sure if parent’s position: relative is the culprit. But that’s a compulsory style.
I also tried with z-index for img but no avail.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:14:36+00:00Added an answer on June 10, 2026 at 5:14 am

    Replace the deprecated .live() by .on() as you’re using jQuery 1.7+.

    $('#parent > img').on('click', function(e) {
    

    Fiddle

    Or, if you need the event delegation (e.g. in case you’re adding content dynamically to #parent):

    //run this line when #parent is in the DOM
    $('#parent').on('click', '> img', function(e) {
    

    Fiddle

    .live bubbles the event all the way up to the document to then check if the given selector matches the target element, by then you can’t stop the event propagation anymore. From the docs:

    Calling event.stopPropagation() in the event handler is ineffective in stopping event handlers attached lower in the document; the event has already propagated to document.

    Also, to answer the “parent takes precedence” question, that’s not case. When you call .live, you’re actually attaching a handler to the document.

    In this case, the handler attached through .click(function(){}) (which in jQuery 1.7+ is a shorthand for .on('click'[, null], function(){}), executes before the handler attached to the document, which is the expected event propagation bubbling behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to have a child DIV within a parent container DIV
Given that I have a button within a div: <div id=result> <a href='#task5'> <img
I have multiple sections... within these sections there are few child elements... I need
I have a collection of floating divs within another div. The child divs are
Say I have a div with overflow-x:scroll and overflow-y:hidden. Within that div there is
I'm have a web page where I have a div within which there is
I have a container div that contains some img tags. When I click on
I have three divs, within a content div. Container width 70%. Within that I
I have a div (.header) contained within other divs. When my page loads, momentarily
I have 2 internal div's within a main div JSfiddle - http://jsfiddle.net/uwdnH/ Illustration -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.