javascript - e.target is body on click when context menu is visible -


i have event:

$(document).on('click', function(e) {    var $target = $(e.target);    if ($target.is('.element')) {       console.log('element');    } }); 

and have issue:

when right click show context menu , click on .element (when context menu visible) e.target body not .element in chrome.

how can detect if click on .element?

i've resolve issue adding code:

function inside(element, x, y) {     var offset = element.offset();     var width = element.outerwidth();     var height = element.outerheight();     return (x > offset.left && y > offset.top &&             x < (offset.left + width) && y < (offset.top + height)); }  $(document).on('click', function(e) {    e = e.originalevent;    var inside_elements = $('.element').get().filter(function(element) {        return inside(element, e.pagex, e.pagey);    });    if (inside_elements.length) {       console.log('element');    } }); 

edit: , found solution using this:

$(document).on('click', function(e) {    e = e.originalevent;    var node = document.elementfrompoint(e.pagex, e.pagey);    var $target = $(node);    if ($target.is('.element')) {       console.log('element');    } }); 

edit2 weird enough don't happen when i've try recreate issue in codepen, maybe it's focus/blur of textarea on click.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -