Вы можете попытаться передать событие на B
(используя jQuery):
( псевдокод )
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/
Обновление
используя такую функцию:
// 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;
};
вы можете получить элементы для заданной координаты x / y. Это немного глупо и требует дополнительного тестирования.
$('#outer').on('click', function (evt) {
var elements = elementsFromPoint(
evt.pageX + $(this).offset().left,
evt.pageY + $(this).offset().top,
this
);
console.log(elements);
});
демо: http://jsfiddle.net/hzErh/1/
Обновление 2 : эта версия должна обеспечивать лучшую производительность для многих элементов:
// 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;
};
демо: http://jsfiddle.net/CTdZp/2/