0

Under my app i wonder which element is catching my click ,

I ve tried to to this test :

$(document).on('click', event => {
 const clickedElement = $(event.target);
 console.log(clickedElement);
});

When clicking under some elements its seems that jquery is not seeing the click ,

nothing is printed in console

How may is force this actions ?

Suggestions ?

firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
  • https://stackoverflow.com/questions/16091823/get-clicked-element-using-jquery-on-event – Koosh Oct 24 '18 at 12:57
  • 4
    `$('document')` needs to be `$(document)`. Voting to close as a typo – Rory McCrossan Oct 24 '18 at 12:58
  • @RoryMcCrossan it is .. still not ctaching the click – firasKoubaa Oct 24 '18 at 13:02
  • With quotes removed, It has to work. If still not, wrap that code with `$(document).ready(function(){` and `});` – Louys Patrice Bessette Oct 24 '18 at 13:03
  • @firasKoubaa are you sure? It works fine here now you've corrected the selector: http://jsfiddle.net/52mq0gkj/ – Rory McCrossan Oct 24 '18 at 13:05
  • Code seams to be correct. Is jQuery loaded? Or are there some console errors? – brandt.codes Oct 24 '18 at 13:20
  • likely the document or jquery hasn't loaded at the time of binding.tying wrapping it up with document ready – digital-pollution Oct 24 '18 at 13:30
  • @digital-pollution if `$(document).on()` doesn't work "because it's not loaded yet", how would `$(document).ready` work? :P The document definitely exists for both of those statements. – Taplar Oct 24 '18 at 14:21
  • so you're saying it's just specific elements that don't get registered? Is it paert of a bigger application with other factors? We might need a working example for helping on that. By all means your code is correct and if wrapping in doc ready has no effect then it'll be some other factor not demonstrated in the code sample. – digital-pollution Oct 25 '18 at 07:46

0 Answers0