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 7729125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:53:23+00:00 2026-06-01T05:53:23+00:00

On my web page I have two divs, A and B: The DOM looks

  • 0

On my web page I have two divs, A and B:

enter image description here

The DOM looks as follows (simplified). The main thing to note here, is that the divs are on the same level in the DOM hierarchy and they are not ordered by anything. Also, the outer div does not only contain A and B but also more divs C,D,E etc. B may not necessarily be overlapped by A. It could also be C, lying behind A.

<div>
    <div style="...">B</div>
    <div style="...">A</div>
</div>

A click handler is attached to the outer div, capturing mouse click events on A or B in the bubbling phase. A click into the intersection of A and B will cause an click event on A which bubbles up to my click handler that is now fired.

Now the problem: Under certain conditions the handler decides that the event should not be handled by A but should belong to B. If an event should be handled by B, the same click handler will be fired, but the event objects currentTarget property will be B instead of A.

How can I achieve this?

I’ve already looked at css3 pointer-handler and some event dispatching methods in JS, but could not really come up with a solution here.

Possible solution 1 (not cross-browser compatible) ?:

I think i might be possible to use the pointer-events css3 property. If the handler decides that the event should be handled by B, it sets the pointer-events to none. Then, it retriggers the mouse click. Question here: Is it possible to retrigger a mouse click with only the coordinates, not specifying a specific element?

Anyway, the support of pointer-events is limited: http://caniuse.com/pointer-events

  • 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-01T05:53:24+00:00Added an answer on June 1, 2026 at 5:53 am

    You can try to pass the event to B (using jQuery):

    (pseudo-code)

    var $A = $('#A'), $B = $('#B');
    
    $B.on('click', function () {
      console.log('B clicked');   
    });
    
    $('#outer').on('click', function (evt) {
        if (Math.random() < 0.1) { // << pseudo condition
            $B.trigger(evt);
        }
    });​
    

    http://jsfiddle.net/hzErh/


    Update:

    using a function like this:

    // this function should (did not enough testing) return all elements at a given
    // point in the order of top to bottom.
    var elementsFromPoint = function (x, y, root) {
      var buffer = [], result = [], el, i = 0, lim;
    
      while ((el = document.elementFromPoint(x, y)) && [root, document.body, document.body.parentNode].indexOf(el) < 0) {
        result.push(el);
        buffer.push({el: el, visibility: el.style.visibility});
        el.style.visibility = 'hidden';
      }
    
      for (lim = buffer.length; i < lim; i += 1) {
        buffer[i].el.style.visibility = buffer[i].visibility;
      }
    
      return result;
    };
    

    you can get the elements for a given x/y coordinate. It’s a bit hacky and needs more testing though.

    $('#outer').on('click', function (evt) {
      var elements = elementsFromPoint(
        evt.pageX + $(this).offset().left,
        evt.pageY + $(this).offset().top,
        this
      );
    
      console.log(elements);
    });
    

    demo: http://jsfiddle.net/hzErh/1/


    Update 2: this version should give better performance for many elements:

    // this function should (did not enough testing) return all elements at a given
    // point, though the order is not representative for the visible order.
    var elementsFromPoint = function (root, x, y) {
      var result = [], i = 0, lim = root.childNodes.length, bb;
    
      for (; i < lim; i += 1) {
        bb = root.childNodes[i].getBoundingClientRect();
        if (bb.left <= x && x <= bb.right && bb.top <= y && y <= bb.bottom) {
          result.push(root.childNodes[i]);
        }
      }
    
      return result;
    };
    

    demo: http://jsfiddle.net/CTdZp/2/

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

Sidebar

Related Questions

I have created a web page that has two bars across the top of
I have two jQuery autocomplete textboxes on a mvc web page. One that returns
please consider this scenario: we have two web page. a simple page that contains
So I have two Google maps on the same web page. The page is
On my web page I have two hyper links which do almost similar thing
I have a webpage with two side by side overflowing divs that split the
I have two fields on my web page ie: BookAuthor and BookDescription.On submit,the page
I have the following problem. I got two forms on my web page. On
I am using Page.Isvalid function in my web page.I have two buttons in my
I have two web pages that I am trying to send information between. One

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.